How objects get wired into bigger structures without every wire tangling into every other wire. Adapters translate, decorators layer, facades hide, proxies stand in for the real thing. Eight patterns, all about composition, none of them about creation.
- Adapter Translates one interfaceâs calls into anotherâs, so old and new code can talk without either one changing.
- Bridge Splits two independent hierarchies, like vehicle and workshop, apart so either can grow without multiplying the otherâs class count.
- Composite Lets a tree of leaves and containers, like files and directories, get traversed through one shared interface, no isDirectory checks needed.
- Decorator Wraps an object in layers of optional, combinable behavior instead of writing a subclass for every combination.
- Facade Wraps a fixed sequence of subsystem calls behind one method, so callers stop re-implementing the same coordination logic.
- Flyweight Shares identical state across many objects and passes the unique part in per call, cutting memory that would otherwise scale with object count.
- Private Class Data Locks a classâs internal state behind getters only, so nothing outside it, not even its own subclasses, can mutate it after construction.
- Proxy Stands in for a real object, deferring its expensive construction or adding checks, while callers canât tell which one theyâre holding.
Comments