Composing objects.
WHAT PROBLEM THEY ADDRESS
Combining objects into larger structures without rigid coupling.
WHAT AN ADAPTER DOES
Translates one interface into another.
When it helps: integrating a library whose interface does not match your code.
WHAT A FACADE DOES
Provides a simple interface to a complex subsystem.
When it helps: hiding complexity from callers who need only part of it.
WHAT A DECORATOR DOES
Adds behaviour by wrapping, without changing the wrapped thing.
When it helps: adding logging, caching or validation around existing behaviour.
WHY THAT IS PREFERABLE TO INHERITANCE
It composes, so several behaviours can be combined.
WHAT A PROXY DOES
Stands in for something, controlling access to it.
When it helps: lazy loading, access control, remote access.
WHAT A COMPOSITE DOES
Treats individual objects and groups uniformly.
When it helps: tree structures, where a node and a leaf should be handled the same way.
WHAT THESE SHARE
Adding a layer of indirection.
WHAT THAT COSTS
Another thing to follow when reading the code.
WHAT TO WEIGH
Whether the flexibility is needed.