Understanding the OO concept of polymorphism
In this section, we will introduce an essential object-oriented concept, polymorphism.
From Chapter 5, Exploring Classes in Detail, and Chapter 6, Implementing Hierarchies with Single Inheritance, you now understand the key OO ideas of encapsulation, information hiding, generalization, and specialization. You know how to encapsulate a class, how to build inheritance hierarchies using single inheritance, and the various reasons to build hierarchies (such as supporting Is-A relationships or for the lesser-used reason of supporting implementation inheritance). Let’s begin by extending our basic OO terminology by exploring polymorphism.
When a base class specifies an operation such that a derived class may redefine the operation in its class with a more suitable method, the operation is said to be polymorphic. Let’s revisit our definitions of operation and method, as well as their implications, to understand how these concepts...