CHAPTER 6 ■ OBJECTS AND DESIGN
Figure 6–10. A unidirectional association
If each class has a reference to the other, we can use a double-headed arrow to describe a
bidirectional relationship, as in Figure 6–11.
Figure 6–11. A bidirectional association
You can also specify the number of instances of a class that are referenced by another in an
association. You do this by placing a number or range beside each class. You can also use an asterisk (*)
to stand for any number. In Figure 6–12, there can be one Teacher object and zero or more Pupil objects.
Figure 6–12. Defining multiplicity for an association
In Figure 6–13, there can be one Teacher object and between five and ten Pupil objects in the
association.
Figure 6–13. Defining multiplicity for an association
Aggregation and Composition
Aggregation and composition are similar to association. All describe a situation in which a class holds a
permanent reference to one or more instances of another. With aggregation and composition, though,
the referenced instances form an intrinsic part of the referring object.
In the case of aggregation, the contained objects are a core part of the container, but they can also
be contained by other objects at the same time. The aggregation relationship is illustrated by a line that
begins with an unfilled diamond.
In Figure 6–14, I define two classes: SchoolClass and Pupil. The SchoolClass class aggregates Pupil.