Objects by Design Forums Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home  
Objects by Design Forums : Powered by vBulletin version 2.3.5 Objects by Design Forums > Main Forums > Object-Oriented Design and Patterns > Aggregation Vs Composition
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
contactdeena
Junior Member

Registered: Jun 2006
Location:
Posts: 1

Aggregation Vs Composition

Hi

Under what scenario's should we decide to use Aggregation or Composition? Can somebody please quote some examples?

regards
Deena

Report this post to a moderator | IP: Logged

Old Post 07-05-2006 10:03 AM
contactdeena is offline Click Here to See the Profile for contactdeena Click here to Send contactdeena a Private Message Find more posts by contactdeena Add contactdeena to your buddy list Edit/Delete Message Reply w/Quote
vsatija
Junior Member

Registered: Oct 2005
Location:
Posts: 7

Hi,

Let me tell you the difference between aggregation and composition.

Both represents 'has a' kind of relationship i.e. the typical whole/part relationship. Difference lies in the constraint of the life-time of the contained object. In composition the contained object is destroyed once the container object destroys where-as in aggregation it is not so.

This is the reason in composition the contained object can't be shared between two containers, whereas in aggregation it is possible.

For eg. There is a realtime example. There are two adjacent rooms, the wall that is common to both is shared by both the rooms. So if we design the room and wall classes, then relation ship between wall and room will be aggregation since if one room destroyes still the common wall is there to support the another room.

I hope above explanation is fine.

Regards,
Vipin Satija
vsatija@yahoo.com

Report this post to a moderator | IP: Logged

Old Post 12-12-2006 07:43 AM
vsatija is offline Click Here to See the Profile for vsatija Click here to Send vsatija a Private Message Find more posts by vsatija Add vsatija to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 11:56 PM. Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 

< Contact Us - Objects by Design >

Powered by: vBulletin Version 2.3.5
Copyright ©2000 - 2018, Jelsoft Enterprises Limited.
Copyright 1999-2005, Objects by Design, Inc.