Decorator

E173611

The Decorator is a structural design pattern that allows behavior to be dynamically added to individual objects by wrapping them in flexible, reusable decorator classes.

All labels observed (4)

Label Occurrences
Decorator pattern 3
ConcreteDecorator 1
Decorator canonical 1

How this entity was disambiguated

Statements (49)

Predicate Object
instanceOf software design pattern
structural design pattern
alsoKnownAs Wrapper pattern
linked to: Decorator
applicableWhen extending behavior of individual objects, not entire classes
object responsibilities should be added or removed dynamically
subclassing is impractical or leads to many subclasses
authors Erich Gamma
John Vlissides
Ralph Johnson NERFINISHED
Richard Helm
avoids class explosion from excessive subclassing
belongsTo Gang of Four design patterns
category object structural pattern
commonLanguageSupport C#
C++
Java
JavaScript
Python
consequence can make debugging and configuration more complex
increases number of small objects in a system
preserves original object interface
definesRelationship ConcreteDecorator adds responsibilities to Component
Decorator implements same interface as Component
Decorator maintains reference to a Component
describedIn Design Patterns: Elements of Reusable Object-Oriented Software
differsFrom Adapter changes interface, Decorator preserves interface
Proxy controls access, Decorator adds responsibilities
exampleUseCase adding encryption or compression to I/O streams
adding responsibilities to logging components
adding scrollbars to a window in GUI frameworks
adding validation or caching to service calls
intent Attach additional responsibilities to an object dynamically
Provide a flexible alternative to subclassing for extending functionality
keyProperty decorators are transparent to clients
decorators can be combined in different orders
multiple decorators can be stacked
originYear 1994
relatedTo Adapter pattern
linked to: Adapter

Composite pattern
linked to: Composite

Proxy pattern
structureElement Component interface
ConcreteComponent
linked to: Composite

ConcreteDecorator
linked to: Decorator

Decorator abstract class
supports open-closed principle
runtime behavior extension
single responsibility principle
typicalOperation add pre-processing or post-processing around forwarded calls
forward requests to wrapped component

How these facts were elicited

Referenced by (6)

Full triples — surface form annotated when it differs from this entity's canonical label.

Adapter relatedTo Decorator pattern
linked to: Decorator
Decorator alsoKnownAs Wrapper pattern
linked to: Decorator
Decorator structureElement ConcreteDecorator
linked to: Decorator
Chain of Responsibility relatedTo Decorator pattern
linked to: Decorator
Strategy relatedTo Decorator pattern
linked to: Decorator