Inheritance vs Composition Trade-offs
Compare inheritance and composition and pick the right tool for the design.
Two Ways to Reuse Code
You can reuse code by inheriting from another class or by composing it as a member. Both have their place.
Inheritance: "Is-a"
Use inheritance when the derived class genuinely is a special kind of the base.
class Vehicle {};
class Car : public Vehicle {}; // a Car IS a Vehicle
class SportsCar : public Car {};All lessons in this course
- Single and Multiple Inheritance
- Virtual Functions and the vtable
- Abstract Classes and Pure Virtual Methods
- Inheritance vs Composition Trade-offs