Using composition rather than inheritance to add behavior

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.100.219