Drawing a line between objects implies there is some kind of interaction between those objects.
Could be as simple as one object is calling a method of another object.
Objects being made of other objects.
Known as the "Has-A" relationship:
- A motorbike has a engine
- A computer has a circuit board
- A house has rooms
In UML it is represented by an unfilled diamond head:
Shows an object contains N other objects.
Optionally, can have Multiplicity indicators to show the number of objects interacting, with * representing 0 to many
The dependency level indicated by the multiplicity indicators between objects is referred to as the Cardinality level.
Is also aggregation but more specifically implies ownership.
In UML, composition is show with a filled diamond connector between two objects.
One object is composed of other objects. e.g. a book is composed of many pages:
When an object is made up (is composed) of other objects, it means that when it is destroyed then so too are the contained objects. e.g. if the House object were deleted, then all the associated Rooms objects should be deleted too, and should not be expected to be shared with any other part of the application.
Whereas, in the aggregation example, if the car show room were deleted, the cars could be expected to live on their own.
Composition implies ownership, aggregation does not