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.

When to prefer inheritance to composition
from Hillel Wayne ✉️