Liskov substitution principle
This principle is based on the principle of substitutability between a parent class and child class. When you use inheritance, an external object should be able to use a class or a subclass without knowing about it. It means that the implementation of a subclass should be compatible with the use of the parent class (it should not break the use for an external object).
Code example
In the previous implementation, the function bark print something and return None for BigDog, but the bark function for BigDogWithVoiceLoss return a string and print nothing. Therefor, BigDogWithVoiceLoss cannot be used as a BigDog even when BigDog is his parent close, thus violating the Liskov substitution principle. This principle applies to function (parameters, return type, ...), attributes of a class ... a child class should never modify function parameters and return type or attributes type that are defined in the parent class.References
- https://en.wikipedia.org/wiki/Liskov_substitution_principle
- "Clean Architecture: A Craftsman's Guide to Software Structure and Design" by Robert Martin