Problem Statement
Explain how composition improves flexibility compared to inheritance, giving an example.
Explanation
Composition means that a class holds references to other classes rather than inheriting from them. This 'has-a' relationship allows behaviour to be changed at run time by replacing composed objects rather than modifying class hierarchy. /n/n For example consider a `Car` class instead of inheriting from `ElectricEngineCar` or `GasEngineCar`, the `Car` class has a reference to `Engine` interface and you can inject `ElectricEngine` or `GasEngine` implementations. This means you can change engine type without changing the Car class or using complex inheritance. /n/n Composition thus supports design flexibility, easier testing (you can mock the engine), and lower coupling than deep inheritance structures.