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 languages including Python. We introduce this new technique in Chapter 12 and will ask you to reconsider the simulation as a programming exercise.

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

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