Comparison
Adapter patternvsDecorator pattern
Adapter pattern
the library's method was called differently and returned the wrong shape, so you wrote a class that speaks both.
A wrapper that converts one interface into another the caller already expects, so two things that were not designed together can work together. The intent is incompatibility, and that is what separates it from the other three wrappers: the adapter's interface is deliberately different from the thing it wraps. It is the pattern that keeps a third-party SDK from spreading through a codebase, which is the same argument the anti-corruption layer makes at the service boundary.
Full entry →Decorator pattern
you wrapped the same interface in retries, then logging, then caching, and the caller still sees one thing.
A wrapper that implements the very same interface as the object it wraps, adding behaviour before or after delegating. Because the interface is unchanged it stacks: three decorators around one object is still that one interface, which is what separates it from adapter and facade. Order matters and is easy to get wrong — caching outside retries caches the eventual success, caching inside retries caches the failure — and that is nearly always the bug.
Full entry →