Exercises
-
11.3 (Composition as an Alternative to Inheritance) Many programs written with inheritance can be written with composition instead, and vice versa. Rewrite class
BasePlusCommissionEmployeeof theCommissionEmployee–BasePlusCommissionEmployeehierarchy to use composition rather than inheritance. After you do this, assess the relative merits of the two approaches for designing classesCommissionEmployeeandBasePlusCommissionEmployee, as well as for object-oriented programs in general. Which approach is more natural? Why? -
11.4 (Inheritance Advantage) Discuss the ways in which inheritance saves time during program development and helps prevent errors.
-
11.5 (Protected vs. Private Base Classes) Some programmers prefer not to use ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access