1
JavaAdvanced#design-patterns
Inheritance creates tight is-a coupling to a parent class and can break encapsulation across hierarchy changes. Composition builds has-a relationships by combining objects, offering more flexibility, easier testing, and avoiding fragile base class problems.
// Inheritance (tight coupling)
class Car extends Engine {}
// Composition (flexible)
class Car { private Engine engine; Car(Engine engine) { this.engine = engine; } }