Aggregation and Composition

UML has special notation for composition and aggregation:

Composition in UML

Composition is the relationship between an assembly and its components.

The components are not generally shared by multiple assemblies.

Components are created when the assembly is created, copied when the assembly is copied, and destroyed when the assembly is destroyed.

Assemblies contain their components by value.

class Car
{
   Engine engine;
   // etc.
};

Aggregation in UML

Aggregation is the relationship between a container and its contents, a set and its members, a collection and its items.

Members of an aggregate can simultaneously belong to other aggregates. Copying or destroying an aggregate usually doesn't copy or destroy the members.

Aggregates usually contain their members by reference.

class Fleet
{
   set<Car*> members;
   // etc.
};

Aggregation and Composition in C++

Templates

STL

Algorithms

Aggregation and Composition in Java

Philosophy of Partonomic Relationships