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
- Notes
- software
- When to Prefer Inheritance to Composition
-
Permalink to
2023.NTE.450
- Edit
← Previous | Next → |
Note on When to Prefer Inheritance to Composition via Hillel Wayne | Note on The Black Swan via Nassim Nicholas Taleb |