7 Design subclasses right
This chapter covers
- When to use function overriding and overloading
- The Liskov Substitution Principle ensures proper subclasses
- Designing classes and subclasses properly with “is-a” and “has-a” relationships
- The Favor Composition over Inheritance Principle increases code flexibility
- Factory classes also increase code flexibility and prevent hardcoding
- Using Programming by Contract correctly when designing subclasses
As described in section 1.7, inheritance is one of the main concepts of object-oriented programming. When we create an application with class hierarchies of superclasses and subclasses, we must design the subclasses right to achieve a well-designed application.