As noted earlier in the Liskov Substitution Principle section, there are two general ways to add features to a class definition:
- Inheritance to extend a class by creating a subclass
- Composition of a new class from one or more other classes
In general, these choices are always present. Every object-oriented design decision involves choosing between inheritance and composition.
To make the decision more nuanced, Python allows multiple inheritance. While combining multiple mixing classes is partially a kind of inheritance, it is more fundamentally an exercise in composition.
The LSP can lead to avoiding inheritance in favor of composition. The general suggestion is to reserve inheritance for those situations where the child class can fully replace the parent class. When features are changed in some way to create a child that...