ASSOCIATION AND AGGREGATION RELATIONSHIP ASSOCIATION An association represents

  • Slides: 10
Download presentation
ASSOCIATION AND AGGREGATION RELATIONSHIP

ASSOCIATION AND AGGREGATION RELATIONSHIP

ASSOCIATION An association represents a general binary relationship that describes an activity between two

ASSOCIATION An association represents a general binary relationship that describes an activity between two classes. It allows objects to call methods in other objects through object references � The UML class diagram uses solid line that connects the two classes to represent association relationship between classes as shown below: � Student Register (Course) Course

Example of Association Given an association of two classes i. e. student registers up

Example of Association Given an association of two classes i. e. student registers up to 10 courses. 1. . 60 Student register. Course 10 Course Program Student. java, Test. Associate. java and Course. java will illustrate the concept of Association

AGGREGATION Aggregation is a special form of association, which represents an ownership relationship between

AGGREGATION Aggregation is a special form of association, which represents an ownership relationship between two classes. � Aggregation models has-a relationship. It is usually represented as a data field in the aggregated class. � In other words, an aggregation object is composed of other objects. � The UML class diagram uses a hollow/empty diamond be attached to the ends of association lines to indicate aggregation. � Student Address

Student - firstname: String - lastname: String - home. Address : Address - college.

Student - firstname: String - lastname: String - home. Address : Address - college. Address : Address + Student (String, Address, Address) + to. String(): String Address - street: String - city : String - state : String - zip : long + Adress (String, long) + to. String(): String Student. Test CLASS DIAGRAM OF AGGREGATION CONCEPT + main(String[]): void Student. java, Address. java and Student. Test. java Are Java programs that show aggregation concept

COMPOSITION Composition represents an exclusively owned relationship by an aggregating object. � It implies

COMPOSITION Composition represents an exclusively owned relationship by an aggregating object. � It implies a whole/part relationship. � The UML class diagram uses a solid diamond be attached to the ends of association lines to indicate aggregation � Student Name

COMPOSITION – cont. In composition, the object is created inside the composed class �

COMPOSITION – cont. In composition, the object is created inside the composed class � while in aggregation, the object is created outside the aggregated class. � In composition, when an object is destroyed, other objects belonging to it should be destroyed as well �

CLASS DIAGRAM Person Name - name: Name - address: Address - firstname: String -

CLASS DIAGRAM Person Name - name: Name - address: Address - firstname: String - lastname: String + Person (Name, Address) + get. Name() : Name + to. String(): String + Name (String, String) + get. Full. Name(): String Address Person. Test + main(String[]): void - street: String - city : String - state : String - zip : long + Adress (String, long) + get. Full. Address(): String