What Does Composition Over Inheritance Mean?
A complete guide to the Composition Over Inheritance design principle: the LEGO-and-costume-shop analogy, the formal definition and its Gang of Four origins with a fair acknowledgment of the original nuance, the fragile base class problem illustrated with the classic Bird-Penguin example, a full has-a versus is-a comparison, a step-by-step build of a Bird class using swappable FlyBehavior and SoundBehavior interfaces (essentially Strategy pattern), a five-row comparison table, real-world examples across Unity components, Go, React, and Strategy/Decorator patterns, honest strengths and trade-offs, when inheritance still makes sense (with a Shape-Polygon-Rectangle-Square depth warning), common pitfalls (composing everything, deep composition chains, forgetting interfaces, treating the preference as an absolute rule), and a quick tour across Java/C#, Go, Python, and Rust.