Polymorphism is one of the three pillars of the object-oriented paradigm and the last feature we need to add to our studies to have a fully object-oriented system. Polymorphism best shows its power in larger, more complex problem solutions - larger and more complex programs than we have time to write in CS 1410. So, our approach focuses on the syntax, meaning, and basic use of polymorphism with the promise that you will see polymorphism demonstrated in advanced courses.
There are two common ways of thinking about polymorphism:
Function binding. One of the compiler's tasks is binding a function's name, as it appears in a function call, to the machine instructions compiled from the function's body. The compiler can complete the binding for "normal" (i.e., non-polymorphic) functions at compiletime. Polymorphism requires at least two overridden functions. Having multiple functions with the same signature prevents the compiler from unambiguously choosing between the functions, delaying function binding until the program runs.
Responding to a message. While studying milti-class programs, we learned that "objects communicate, and therefore cooperate, by sending messages to each other." From this perspective, polymorphism means that the way an object responds to a message depends on the kind of object receiving the message. If we send an object the draw message (i.e., we call its draw function) a Circle object responds by drawing a circle and a Rectangle object responds by drawing a rectangle.
Know
The five requirements for polymorphism
Inheritance
Function overriding
Upcasting
Virtual functions
Pointer or reference variables (polymorphism cannot operate through an automatic or local variables)
It's not enough to memorize the requirements (practicing computer scientists are rarely asked to recite them). You must be able to identify the requirements in code and understand the code's behavior based on their presence or absence
How a polymorphic function call behaves
The syntax for writing a virtual function
How to write a pure virtual function and understand the impact pure virtual functions have on classes
The difference between concrete and abstract functions