The UML class diagram can be used to show aggregate associations between classes. This section shows you how to use the UML class diagram to express simple and composite aggregation.
Figure 10-1 shows a UML diagram expressing simple aggregation between classes Whole and Part. The association is expressed via the line that links Whole and Part. The simple aggregation property is denoted by the hollow diamond shape used to anchor the line to the Whole class. Simple aggregation represents a uses relationship between the aggregate and its parts since the lifetime of part objects are not controlled by the aggregate.
Figure 10-1: UML Diagram Showing Simple Aggregation
Figure 10-2 shows two different simple aggregate classes, Whole A and Whole B, sharing an instance of the Part class. Such a sharing situation may require thread synchronization. (See chapter 16 - Threads)
Figure 10-2: Part Class Shared Between Simple Aggregate Classes
Composite aggregation is denoted by a solid diamond adorning the side of the aggregate class. Composite aggregate objects control the creation of their part objects which means part objects belong fully to their containing aggregate. Thus, a composite aggregation denotes a contains or has a relationship between whole and part classes. Figure 10-3 shows a UML diagram expressing composite aggregation between classes Whole and Part.
Figure 10-3: UML Diagram Showing Composite Aggregation