Decorator Pattern
Decorator dynamically adds responsibilities to an object by wrapping it with another object implementing the same abstraction. It is an alternative to creating many subclasses for combinations of optional behavior. Multiple decorators can be stacked, which makes the design flexible. A common example is adding logging, caching, authorization or compression around an existing service.
Decorator implements the same abstraction as the wrapped object.
Behavior can be added without modifying the original implementation.
Decorators can be composed or stacked.
Useful for cross-cutting behavior such as logging, caching and authorization.
Too many nested decorators can make debugging and understanding execution order difficult.