Composition

A composition is a stronger form of aggregation, with strong ownership and coincident lifetime as part of the whole [BRJ99]. In a composition association, the whole is responsible for the creation and destruction of its parts. Once a part is created, it belongs to the whole and when the whole is destroyed, the part is destroyed too. In a composition, a part may belong to only one whole at a time.

As an example, let us consider constructing a UML diagram that represents a plant and its relationships with its root, stem, and leaves systems. The relationship between plant and its systems can be presented as a composition. Plant will play the role of the whole and its systems will be its parts. Plant owns its root, stem, and leaves systems. A stem system can only belong to one plant at a time. In most cases if the plant dies, so do its root, stem, and leaves systems. The UML presentation of a composition is shown in Figure 4-12.

Figure 4-12. Plant is considered as a composition of its root, stem, and leaf systems.
0 0

Post a comment