Decorator Pattern
Status: draft · Confidence: medium (0.635) · Basis: verified_sources
Quality notes: generic_source_homepage, no_verified_sources, partial_source_verification
## TL;DR Attaches additional responsibilities dynamically, providing flexible alternative to subclassing. Decorators conform to the same interface, enabling transparent stacking. ## Core Explanation Example: `new CompressedStream(new EncryptedStream(new FileStream()))`. Python @decorator syntax. ES7 decorators (Stage 3). React HOC (Higher-Order Components) is a decorator pattern applied to components. Middleware pattern (Express, Koa) is a variant. ## Further Reading - [Design Patterns (Gang of Four)](undefined) ## Related Articles - [Adapter Pattern](../adapter-pattern.md) - [Command Pattern](../command-pattern.md) - [Factory Method Pattern](../factory-method-pattern.md)