Should I be inheriting from this type?

Composition Over InheritanceComposition Over Inheritance
Composition is a method of writing OOP code. It attempts to solve the same [[Software Design]] problem as Inheritance, but instead of relying on inheriting features from the parent class, c...
as OOP principle doesn't have much value if we don't invest time to think about the cases when Inheritance should be favored over Composition.

If a class would expose all public methods of another class, it's a good use case for inheritance. If anywhere you use Animal in your application, you could just as well use Dog without any issues, Dog inherits Animal is a good idea. See Liskov Substitution PrincipleLiskov Substitution Principle
Liskov Substitution Principle is the third of the [[Software Design]] [[SOLID Principles]] in [[OOP]]. It states this:

If S is a subtype of T, then objects of type T may be replaced with objects o...
.

If a class wants only part of the behaviour exposed by another class, you'd be much better off with Composition.


Status: #🌲