wood burning stoves 2.0*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes UML : composition vs aggregation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "UML : composition vs aggregation" Watch "UML : composition vs aggregation" New topic
Author

UML : composition vs aggregation

Raj Mohan
Ranch Hand

Joined: Sep 26, 2000
Posts: 73
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

Joined: Apr 04, 2001
Posts: 93
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

Joined: Sep 26, 2000
Posts: 73
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

Joined: Apr 04, 2001
Posts: 93
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

Joined: Apr 05, 2000
Posts: 1441
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


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Sep 26, 2000
Posts: 73
Thanks Danl, John, Avery. Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UML : composition vs aggregation
 
Similar Threads
Association /aggregation/composition
What is aggregation.. ??
What is Aggregation
Aggregation and Composition
Association vs Aggregation