ali raza

C#, .Net ,Asp.net and my thoughts

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.

2 responses to “Composition and Aggregation in oops

  1. vimal April 24, 2009 at 8:11 am

    It’s really a organized to simply understandable manner.

  2. Saqlain May 18, 2009 at 10:47 am

    Gud Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: