Aggregation Example Code


Expressing Aggregation In A UML Class Diagram

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.

Simple 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.

image from book
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)

image from book
Figure 10-2: Part Class Shared Between Simple Aggregate Classes

Composite Aggregation

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.

image from book
Figure 10-3: UML Diagram Showing Composite Aggregation




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net