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
posted 19 years ago
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.
posted 19 years ago
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
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.