Explain the is-a relationship, and what are the risks of creating an inheritance hierarchy that is too deep?
Last updated
Is-a means a subclass is a specialized kind of its superclass (SavingsAccount is an Account) and must honor the parent's contract (Liskov Substitution).
Deep hierarchies risk the fragile base class problem (changes ripple down), scattered behavior that is hard to trace, and tight coupling to unneeded inherited features.
Keep hierarchies shallow and use composition or interfaces to add behavior.
- https://dev.to/muhammad_salem/when-inheritance-shines-and-when-it-may-become-problematic-4b91
- https://codilime.com/blog/decoding-inheritance-use-and-misuse/
- https://medium.com/@debby1ee/composition-over-inheritance-in-system-design-f9f714626931
- https://andrewtetzeli.hashnode.dev/challenges-and-solutions-ive-found-in-managing-inheritance-hierarchies-in-object-oriented-programming