7. Mastering Inheritance and Composition
Inheritance and composition play major roles in the design of object-oriented (OO) systems. In fact, many of the most difficult and interesting design decisions come down to deciding between inheritance and composition.
Both inheritance and composition are mechanisms for reuse. Inheritance, as its name implies, involves inheriting attributes and behaviors from other classes. In this case, there is a true parent/child relationship. The child (or subclass) inherits directly from the parent (or superclass).
Composition, also as its name implies, involved building objects by using other objects. In this chapter we will explore the obvious and subtle differences between inheritance and composition. Primarily, ...
Get The Object-Oriented Thought Process now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.