18. Polymorphism: Object Independence

If you’ve made it this far, congratulations! You’re about to scale the highest peak of all in the mountain range of object-oriented concepts: polymorphism. It is the key to making objects truly independent.

Remember that objects—which are instances of classes—are data items that have built-in behavior. More than anything else, this ability of an unknown object to bring in new kinds of behavior—essentially plugging new software into an existing framework—makes good on the promise of object orientation.

A Different Approach to the FloatFraction Class

Virtual functions are at the core of polymorphism. To understand why they are useful, let’s look at an example building on the Fraction class.

The FloatFraction ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.