Composition
Composition indicates that a has-a relationship is being used. When inheritance is not the proper design choice (because the is-a relationship is not appropriate), composition is normally used.
Chapter 9, “Building Objects,” discusses two different types of composition: aggregations and associations. Composition is used when classes are built with other classes. This can happen with aggregation, when a class is actually a component of another class (as a tire is to a car). Or, it can happen with association, when a class needs the services of another class (for example, when a client needs the services of a server).
Aggregations
An aggregation is represented by a line with a diamond at the head. In the car example of Chapter 9, to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access