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,

Inheritance

use composition,

Composition

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

Dynamic Composition