The Decorator pattern, also known as Wrapper, is a structural GoF design pattern by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides that attaches additional responsibilities to an object dynamically. Decorators wrap the object and add behavior transparently, which offers a flexible alternative to subclassing when extension by inheritance is impractical, for example to add formatting, timestamps and filtering to a logger.
GoF-Decorator Pattern
Details
- Full Name
-
GoF Decorator Pattern (Structural)
- Also known as
-
Wrapper
Intent:
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing.
When to Use:
-
To add responsibilities to objects dynamically and transparently
-
When extension by subclassing is impractical
Prompt Example:
"Verwende das GoF-Decorator Pattern, um dem Logger dynamisch Formatierung, Timestamp und Filterung hinzuzufügen."
Related Anchors:
-
GoF Design Patterns (Umbrella)