More polymorphism
We already know that polymorphism means many forms, but what does it mean to us?
Boiled down to its simplest, it means the following:
Note
Any subclass can be used as part of code that uses the super class.
This means that we can write code that is easier to understand, and simpler to change.
Also, we can write code for the super class and rely on the fact that no matter how many times it is subclassed, the code will still work within certain parameters. Let's discuss an example.
Suppose that we want to use polymorphism to help write a zoo management app. We will probably want to have a function, such as feed. Let's also say we have Lion, Tiger, and Camel classes, which all inherit from a parent class called Animal. We will also ...
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