3 ms·
Implementing an abstract class when the concrete implementation conforms to the Liskov Substitution Principle is exactly when inheritance does make sense. You w
by jknupp 16y ago
Implementing an abstract class when the concrete implementation conforms to the Liskov Substitution Principle is exactly when inheritance does make sense. You would do this so that calling code wouldn't need to care that the function required a MySpecialMapClass rather then something that conforms to the AbstractMap interface.
However, if you just think that some of the functions in AbstractMap are useful but plan on creating a totally different class that doesn't conform to the interface, then inheritance is inappropriate.
Code reuse is not a reason to use inheritance; it is a byproduct of it.
- ipreuss 16y agoI think you need to distinguish between interface inheritance and implementation inheritance. The reason to use interface inheritance is to allow polymorphism in a statically typed language. The only reason to use implementation inheritance is code reuse. And yes, you should only do that if the classes conform to the LSP.