Why "prefer composition over inheritance"?
February 21, 2024
- https://veerpalbrar.github.io/blog/2021/06/30/Inheritance-vs-Composition
- choosing “composition over inheritance”, means adding behavior to an object by composing objects instead of using inheritance
- inheritance
- dependency
- backwards compatability
- have to constatly modify child class and override parent functionality
- composition
- small classes with clear responsibilities
- complexity arises with complex classes delegating tasks, and when classes know too much about the implementation of other classes