Vlad's Roam Garden

Powered by 🌱Roam Garden

Composite Simpler Than the Sum of Its Parts

The API of a composite object should not be more complicated than that of any of its components.

All objects in a system, except for primitive types built into the language, are composed of other objects. When composing objects into a new type, we want the new type to exhibit simpler behavior than all of its component parts considered together. The composite object’s API must hide the existence of its component parts and the interactions between them, and expose a simpler abstraction to its peers. Think of a mechanical clock: It has two or three hands for output and one pull-out wheel for input but packages up dozens of moving parts.