Inheritance

Inheritance is a design pattern that is supported by object-oriented programming languages. Inheritance allows a class to inherit properties and behaviors from another class. This promotes code reuse and reduces redundancy.

Inheritance is best reserved for genuine subtyping, where a subclass truly is a specialization of its parent and honors the Liskov substitution principle. For reuse without an "is a" relationship, composition is usually the safer choice – it keeps coupling lower and behaviors swappable at runtime. Composition is a specialization of association, the general class-to-class relationship. Inheritance is also the mechanism Bertrand Meyer originally used to frame the open-closed principle: a base class is closed to modification because its clients depend on its fixed interface, yet open to extension through subclasses that add or override behavior.