Aggregation And Composition

As opposed to the IS A relationship of inheritance, aggregation refers to the HAS A or HAS MANY relationship.

EXAMPLES:

In a UML diagram, the HAS A or HAS MANY aggregation relationship is denoted by a hollow diamond.



NOTE: You can optionally show multiplicity by added an asterisk to represent zero to many.

Composition is a more specialized version of aggregation that implies OWNERSHIP. Which means that one or more objects is “composited” inside of another object so that when the parent object is deletes so will the children objects. For example, if a Document class is composed of Page objects and the Document class is deleted, so will the Page objects. However, it still has a HAS MANY relationship (e.g., Document has many Pages).

In a UML diagram, the HAS A or HAS MANY composition relationship is denoted by a solid diamond.



In contrast, if you refer to the previous mentioned Classroom and Student class as aggregation and you delete the Classroom object, you would still have the Student classes.

NOTE: If the lifetime of an object is dependent on another object, it may be worth showing in a UML diagram.