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).


An aggregation is represented by a line with a diamond at the head. In the car example of Chapter 9, to ...

Get Object-Oriented Thought Process, The, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.