-
Book Overview & Buying
-
Table Of Contents
The C++ Programmer's Mindset
By :
Classes are an encapsulation of data and behavior and should be used in one of two ways. The first is as a structured container that maintains some invariant property that can be used in and queried in algorithms using its methods (for example, std::vector<...>). The second use is as an abstract interface that hides the details, in a similar way to how functions can be used to hide implementation details. This allows you to write code against the abstract interface and use any object that implements it – for example, the IO stream interface in the C++ standard library. Both are examples of abstractions, but go about it in (somewhat) different ways.
When we talk about class-based abstract interfaces, we usually mean dynamic polymorphism (although that is not always the case). Polymorphism (literally translated as “many forms”) is a means by which a class (the interface) can be used in place of any class that implements its interface...