Why C++ Needs Polymorphism - dummies

By Stephen R. Davis

The capability in C++ of deciding at runtime which of several overloaded member functions to call based on the run-time type is called polymorphism, or late binding. Deciding which overloaded function to call at compile-time is called early binding because that sounds like the opposite of late binding.

Overloading a base class function polymorphically is called overriding the base class function. This new name is used to differentiate this more complicated case from the normal overload case.

Polymorphism is key to the power of object-oriented programming. It’s so important that languages that don’t support polymorphism can’t advertise themselves as OO languages. (It’s a government regulation — you can’t label a language OO if it doesn’t support polymorphism unless you add a disclaimer from the Surgeon General, or something like that.)

Without polymorphism, inheritance has little meaning. As an example, think of making nachos in the oven. In this sense, you will be acting as the late binder. The recipe read: Heat the nachos in the oven. It doesn’t read: If the type of oven is microwave, do this; if the type of oven is conventional, do that; if the type of oven is convection, do this other thing.

The recipe (the code) relies on you (the late binder) to decide what the action (member function) heat means when applied to the oven (the particular instance of class Oven) or any of its variations (subclasses), such as a microwave oven (Microwave).

This is the way people think, and designing a language along the lines of the way people think allows the programming model to more accurately describe the world in which people live.