11.8 A Note on Inheritance
As you considered the implementations of the Fish, Bear, and Plant classes, you probably noticed a number of duplications. Each class includes methods that are identical. For example, getX, getY, setX, setY, appear, and hide are all implemented the same way regardless of the class.
This observation leads us to think about the similarities among all life-forms in our simulation. It would make sense if we could somehow take all this duplication, put it in one place, and have all of the life-forms share it. This new implementation would allow us to efficiently add and modify functionality.
The solution that we are proposing is called inheritance—an object-oriented programming technique that is supported by many programming ...
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