Comparison
Decorator patternvsWrapper
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 →Wrapper
the object holds another object and forwards most calls to it, and which pattern that is depends entirely on why.
The shape shared by adapter, decorator, proxy and facade: an object that holds another and passes work through. Because the code looks nearly identical in all four, the name is chosen by intent — to change an interface, to add behaviour, to control access, or to simplify a subsystem — and that is exactly what the interview question is testing. Calling something a wrapper is honest when the intent is genuinely none of the four.
Full entry →