Composition over inheritance — yaygın olarak atıf yapılan bir tasarım ilkesidir ve nesneleri temel sınıflardan miras almak (inheritance) yerine davranışları birleştirerek (composition) oluşturmayı destekler. Inheritance önemli dezavantajlara sahipken, composition bunlardan kaçınır, ancak her ikisinin de yeri vardır.
Inheritance vs composition
INHERITANCE → a class EXTENDS another, inheriting its behavior ("IS-A" relationship):
class Dog extends Animal
COMPOSITION → a class is BUILT FROM other objects/behaviors ("HAS-A" / uses):
class Car { constructor() { this.engine = new Engine(); } } // composes behaviors
→ composition: combine smaller pieces; inheritance: derive from a parent
