So far, we've seen how to use inheritance to add behavior and compose larger structures. This is not always the ideal approach. In many situations, it's better to use a method known as composition instead. This involves using distinct classes in connection without establishing a hierarchical relationship. The chief advantage here is code clarity and flexibility.
In this recipe, we'll see how to use composition.