≡ Menu




Composition and Aggregation in oops

Composition and Aggregation are basically whole/part relationship.

When the lifetime of the part is dependent on or controlled by the whole, the relationship between the whole and part is Composition. 
Which simply means that the part is no more existing when the whole is destroyed.

example : car and engine.
Aggregation : 
When the lifetime of the part is not dependent on or not controlled by the whole, the relationship between the whole and part is Aggregation. 
Which simply means that the part continues to exist when the whole is destroyed.

example : car and stereo

So this typically it means that the part should be shared across multiple objects.
So if one object is destroyed , still the part is continued to be used by other objects
Association : 
Association is simply “uses” relation ship .
It is achieved by simple references in Java.

Point to note is that Aggregation is a special case of Association . OR other way to say is that Aggregation can be achieved by using Association.

{ 0 comments… add one }

Leave a Comment