Composition over Inheritance
June 14, 2021

Inheritance is more rigid as most languages do not allow you to derive from more than one type. With composition, it’s easy to change behavior on the fly with Dependency Injection / Setters.

Instead of using inheritance,


use composition,


It allows you to dynamically switch objects at runtime, like this:

Dynamic Composition