Maintaining compatibility with polymorphism
As we saw in the previous section, we need to design subclasses such that they maintain the superclass’ contract with its clients. For that, the subclasses must maintain the superclass interface, not only explicitly through the function signature and other technical details but also conceptually. A subclass must specialize its superclass. This means that it should do the same behavior as its superclass but for more specific contexts.
Polymorphism, in that sense, comes as a way to extend and even change superclass behavior while maintaining its interface. We usually do that through method overriding. Method overriding is a trademark of polymorphism. It simply means that the subclass can change the implementation details of its superclass methods. To do that, the subclass just needs to declare the method again, of course, maintaining the method’s signature. After that, it needs to change the implementation completely.
We...