Aggregation and Composition - Walking Techie

Blog about Java programming, Design Pattern, and Data Structure.

Monday, June 1, 2020

Aggregation and Composition

Aggregation

Aggregation indicates a relationship between whole and its parts.

For example, A music band is made up of artists. So music band has its artists as its parts and the band is the whole. If the band is broken. Its artists does not have to broken with it. They could still join other band independently or some of them can even start their own band.

Aggregation relationship

In aggregation relationship, When the whole is destroyed, its parts are not destroyed with it.

Composition

Composition is a strong form of aggregation. When we talk about composition relationship, when the whole is destroyed its parts are also destroyed with it. it is a strong form of aggregation.

For example, Here the house has its rooms as part and the house itself as a whole. When the house is destroyed its rooms are also destroyed. In composition relationship each part belongs to only one whole. It means it is not shared with others just like a room in a house. Room is the part of your house, not your neighbors.

Composition relationship

Unlike aggregation relationship, when the whole is destroyed its parts are also destroyed with it.

No comments :

Post a Comment