Composition Over Inheritance
Prefer has-a designs where they fit.
Two Ways to Reuse
You can reuse behavior by inheriting it or by holding another object. The second approach is called composition.
is-a vs has-a
Inheritance models is-a: a Circle is a Shape. Composition models has-a: a Car has an Engine.
All lessons in this course
- Abstract Classes and Abstract Methods
- Implicit Interfaces and implements
- Polymorphism Through Shared Types
- Composition Over Inheritance