11.1. Why Use Inheritance?

To understand why inheritance is appealing, let's design a small application without inheritance and compare it to one that has inheritance. This approach shows you why inheritance is beneficial from a design perspective and why object-oriented languages like C++ are superior to procedure-oriented languages for implementations.

A Procedure-Oriented Approach

Suppose a shipping company handles boxes and letters for customer deliveries. The number of pages determines a letter's shipping cost, and the weight determines a box's shipping cost. Boxes and letters have a source and destination, which also affect shipping costs.

The following procedure-oriented approach uses a single Package structure to handle boxes and letters. ...

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.