O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required