16. Polymorphic Poker

If the only thing that object orientation accomplished was to encourage a more modular programming style, grouping tightly related code and data together, it would still be worthwhile. But there’s more.

The central idea in OOP is that of an intelligent data type. Simply making a function into a member function is only a beginning. Ideally, objects bring with them the knowledge of which function to call; you should be able to switch out one object, switch in another, and get new behavior without changing anything else. You can even switch objects at runtime and get new behavior.

Sound like a dream? But that’s what this chapter is going to explore. We’ll start by examining the Deck class used in the previous chapter, “Object-Oriented ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.