Note on When to Prefer Inheritance to Composition via Hillel Wayne
So here are the benefits of inheritance:
• Unlike composition, you can pass the subclass into functions expecting the parent class. • Unlike interfaces, you can reuse code from the parent class in the child class.
So, here’s when you want to use inheritance: when you need to instantiate both the parent and child classes and pass them to the same functions. That’s it. That’s the use case.
Reference
| ← Previous | Next → |
| Note on When to Prefer Inheritance to Composition via Hillel Wayne | Note on The Black Swan via Nassim Nicholas Taleb |