કમ્પોઝિશન ઓવર ઇનહેરિટન્સ એ વ્યાપક રીતે ટાંકવામાં આવતો ડિઝાઇન સિદ્ધાંત છે — ઓબ્જેક્ટ બનાવવાને વર્તણૂકો જોડીને (કમ્પોઝિશન) બેઝ ક્લાસ્ને વારસો આપવાને બદલે (ઇનહેરિટન્સ) ની બાતમી કરતા. ઇનહેરિટન્સ નોંધપાત્ર ખામીઓ ધરાવે છે જે કમ્પોઝિશન ટાળી જાય છે, તેમ છતાં બંને તેમનું સ્થાન ધરાવે છે.
ઇનહેરિટન્સ વર્સમ કમ્પોઝિશન
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
