CS3340:   Intro OOP and Design

 

UML- Aggregation and Composition

Aggregation and Composition - often interchanged, meaning a whole is assembled from its parts.

Actually,......

Left = Aggregation

  • empty diamond of aggregation designates that the whole maintains a reference to its part.
  • the whole may not have created the part.
  • This is equivalent to a C++ reference or pointer construction.

Right = Composition

  • The filled diamond signifies that the whole is responsible for creating its 'parts'.
  • Which is equivalent to saying that when the whole class is allocated or declared the constructors of the part classes are called followed by the constructor for the whole

 

Composition of a yatch

Composition dependencies

 

composition can be inherited and the same convention as for ordinary associations is used to show this: a / mark on the link Type B inherits components A1 and A2.

Consider a type A with subtypes B and C. A also has components A1 and A2. Class B has components B1 and B2. The composition structure for Class B therefore includes two derived components as shown

 

 

© Lynne Grewe