Composition over inheritance एक व्यापक रूपमा उद्धृत डिजाइन सिद्धान्त हो — वस्तुहरू व्यवहारहरू संयोजन गरेर (composition) बनाउन पसन्द गर्दै बेस क्लासहरूबाट विरासत लिनु (inheritance) भन्दा। Inheritance मा महत्त्वपूर्ण कमजोरीहरू छन् जुन composition ले टाले पनि, दुवै आफ्नो स्थान छन्।
Inheritance बनाम 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
