This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UML : composition vs aggregation

 
Raj Mohan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody please explain the difference between the two. ie. what exactly is aggregation. I am also not clear about Multiple & dynamic classification.
Please help.
regards, Raj.
 
Danl Thompson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think of Aggregation as a "has" or "ownership" relationship. So for example, a room has chairs in it. A chair can only be in one room at a time. But both the room and the chair can exist separately from each other.
I think of Composition in terms of death. A building has rooms, but destroying the building means the rooms are also destroyed. One cannot exist without the other.
James Odell puts it another way. Aggregation is a part-whole relationship whereas composition is an immutable part-whole relationship. He uses the example of a marriage, where the "Marriage of Dan and Nancy" is composed of both Dan and Nancy, and if either partner left, then the "Marriage of Dan and Nancy" would cease to exist.
He also talks about six different kinds of aggregation. So it really can be a complicated subject.
dan'l
 
Raj Mohan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. Danl. So, here in composition, if the main part dies, the sub part also destroyed but in aggregation, the sub part is not destroyed. Please correct me if I am wrong. In this case, how aggregation is different from association. confused. Regards, Raj.
 
Danl Thompson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fowler, in UML distilled, calls aggregation his betes noires. And I agree but to a lesser extent. Aggregation is a kind of association, but it the difference is largely subjective. I think it is largely up to you as a matter of style. I use it (white diamond)to illustrate a collection, but how is that really different from a 1 to many association? Hard to say.
dan'l
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's interesting.
I usually use a one-to-many association to show the relationship between a container/collection class and the classes it holds on to.
John
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Composition is a special form of aggregation. In a composition, the items "belong" to the container, while in a standard association, the items are merely associated with the container.
For example, a room belongs to a building, while a class contains students, but does not "own" them. So a composition would be used to describe the association between a building and its rooms, while a regular association would be used for the relationship between a class and its students.
Rule of thumb:
If the same item can be associated with multiple containers of the same type, then use a regular association. If an item can only appear in one container (of that type), use a composition.
FOr example, a specific room will be part of one and only one building, while a student can appear in multiple classes.
Originally posted by Raj Mohan:
Can anybody please explain the difference between the two. ie. what exactly is aggregation. I am also not clear about Multiple & dynamic classification.
Please help.
regards, Raj.

 
Raj Mohan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Danl, John, Avery. Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic