Difference between Association, Aggregation and Composition


Association is a common type of relationship among classes. When two classes are associated, they can take each other help to serve user requests. There are three types of Association in Software Engineering:

1. Binary Association: If one class is associated with another bidirectionally, then the corresponding objects of the two classes know each other then it is called binary association.

2. Unary Association: In unary association, two (or more) different objects of the same class are linked by the association relationship.

3. Ternary Association: There can be situations where three or more different classes can be involved in an association is called a Ternary association.

Composition and Aggregation:

Composition and aggregation represent part/whole relationships among objects. Objects which contain other objects are called composite objects. The composition/aggregation relationship is also known as “has a relationship”.

Aggregation/composition can occur in a hierarchy of levels. That is, an object contained in another object may itself contain some other object. Composition and aggregation relationships cannot be reflexive. That is, an object cannot contain an object of the same type as itself.