![]() | MSc-IT Study Material January 2011 Edition Computer Science Department, University of Cape Town | MIT Notes Home | Edition Home | |
All object-oriented designers use generalisation-specialisation relationships all the time. They are vital to good design. The relationships we will consider in this section are defined by the UML, but it is not generally agreed that they are a special kind of association at all.
Aggregation is a general term for any whole-part relationship between objects. Its symbol is a white diamond, like this:
This diagram can be read as “an Army is an aggregate of one or more soldiers and one or more weapons”. The aggregation is expressing a loose whole-part relationship between the army and its constituents, where the constituents are not necessarily members of the aggregate. For example, if the army as an entity ceased to exist there would still be soldiers (they would simply be unemployed). This topic has lead to some very heated debate. In practice the distinction between a computer system which works, and a system which does not, is highly unlikely to hinge on whether the designers used aggregations or named associations. An aggregation can usually be replaced by an association called “has” without much loss of clarity.
It is not clear that composition is more expressive than a simple association labelled “contains”. Composition expresses a whole-part relationship where the “parts” are definitely contained within the “whole”.
This example can be read as “a book consists of one or more pages, and one binding”. Note the distinctions between this and the previous example. First, the binding and pages physically comprise the book; it is impossible for the binding and pages to be in one place and book in another. Second, destruction of the book would imply destruction of the binding and pages.