Inheritance
Inheritance is the relationship where a new class is built on top of an existing class. The child class receives fields and methods from the parent and can add to them or override parts of them to become more specific.
βΆArchitecture Diagram
π RelationshipDashed line animations indicate the flow direction of data or requests
If every similar type has to repeat the same fields and behavior, maintenance cost grows and shared rules diverge. Inheritance appeared as the most direct way to avoid rewriting the common part over and over.
Early object-oriented languages often explained reuse and classification mainly through inheritance. Over time, teams learned that deep hierarchies can create fragile coupling, so inheritance is now treated as a more selective tool rather than the default reuse mechanism.
A child class receives the parent's fields and methods by default. It can override selected methods, add new members, and become a more specific type while still fitting into the broader parent-child hierarchy.
Inheritance and composition both address reuse, but they couple code differently. Inheritance assumes a stable is-a relationship, while composition builds behavior through has-a collaboration and is often more flexible when the need is reuse rather than classification.
Inheritance can fit framework base components, task hierarchies, or domain models with a strong and stable subtype relationship. But when the goal is only code reuse, deep inheritance trees often create too much dependence on parent internals.