11.11. Abstract Base Classes

A model that generalizes attributes and behaviors into a single base class that you never instantiate is a good design approach with many problem domains. An example might be a Rental_Property class from which we derive House, Apartment_Building, and Office_Building. We never create a Rental_Property object; instead, we instantiate derived objects that specify a property type. Another example is a Shape class from which we derive Circle, RTriangle (right triangle), and Square. An unspecialized Shape object can never exist because we must specify a Shape type before we use it.

Let's explore this concept further with a Shape hierarchy that manipulates two-dimensional shapes. We'd like to determine the area and perimeter ...

Get Navigating C++ and Object-Oriented Design 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.