Programming FundamentalsIntermediate
Composition
التركيب
Pronunciationkom-po-ZISH-un
Definition
A design principle where you build complex types or functions by combining smaller, simpler ones together rather than relying on deep inheritance hierarchies.
Where you hear it
In code reviews, architecture discussions, and when talking about object-oriented or functional design.
Examples
Instead of using a deep class hierarchy, we used composition to add logging and caching to our service.
React encourages component composition by letting you build large UIs from smaller, reusable parts.
Common mistake
Thinking that composition only applies to classes or objects, when it works equally well with functions and modules.
Keep exploring
More in Programming Fundamentals