An aggregation represents an asymmetric association, in which one of the ends plays a more important role than the other end. The aggregation only applies to one of the roles of an association, regardless of the number of classes involved. Aggregation is represented by adding a small diamond next to the aggregate:
The following criteria imply an aggregation:
The opposite is not always true — aggregation does not necessarily imply the criteria evoked above. If there is any doubt, associations are preferable. In general, it is always necessary to choose the solution that implies the weakest coupling.
Like associations, aggregations may be multiple. As long as no implementation has been chosen, there is no particular constraint on the multiplicity values that may be held by the roles of an aggregation. This means, in particular, that the multiplicity on the aggregate side may be greater than 1. This type of aggregation corresponds, for example, to the concept of co-owner. The following diagram illustrates that people may be co-owners of the same buildings:
The concept of aggregation does not assume a particular form of implementation. Physical containment is a particular case of aggregation referred to as composition.
Attributes are a particular case of aggregation implemented by value — they are physically contained in the aggregate. This type of aggregation is called composition, and is represented within diagrams by a black diamond.
Composition implies a constraint on the multiplicity of the aggregate side: it can only take the values 0 or 1. A value of 0 on the component side would correspond to an uninitialized attribute.
Composition and attributes are semantically equivalent; their graphical representations are interchangeable. The notation of composition is used in a class diagram, while an attribute participates in other relationships within the model. The diagram below illustrates the equivalence between the attribute notation and the composition notation:
An aggregation by value is semantically equivalent to an attribute; it makes it possible to show how an attribute participates in other relationships within the model.
Classes implemented by composition are called composite classes. These classes supply an abstraction of their components.
© 1997 Editions, Eyrolles, Paris, France . All rights reserved.