Conceptual
Login

Python Composition vs Inheritance to Separate Responsibilities

The principle "favor composition over inheritance" holds that object responsibilities should be separated using composition (a "has-a" relationship, where independent classes are combined and delegate to one another) rather than inheritance (an "is-a" relationship, where a class hierarchy of superclasses and subclasses is built). Inheritance introduces the strongest form of coupling in object-oriented programming because subclasses become directly dependent on their superclass's implementation, and using it to separate multiple orthogonal responsibilities produces a combinatorial explosion of subclasses; abstract base classes mitigate this by letting dependents rely on an interface rather than a concrete implementation, which is why abstract base classes reduce coupling while plain inheritance increases it. This concept belongs to object-oriented software design principles, specifically class relationship modeling and coupling/cohesion management as embodied in the Gang of Four design patterns.