Chain of Responsibility
Decorator Design Pattern
Extending an objectís functionality can be done statically (at compile time) by using inheritance however it might be necessary to extend an objectís functionality dynamically (at runtime) as an object is used.
Consider the typical example of a graphical window. To extend the functionality of the graphical window for example by adding a frame to the window, would require extending the window class to create a FramedWindow class. To create a framed window it is necessary to create an object of the FramedWindow class. However it would be impossible to start with a plain window and to extend its functionality at runtime to become a framed window.
ImplementationThe figure below shows a UML class diagram for the Decorator Pattern
DescriptionThe decorator pattern applies when there is a need to dynamically add as well as remove responsibilities to a class, and when subclassing would be impossible due to the large number of subclasses that could result.
Applicability & Examples
Example - Extending capabilities of a Graphical Window at runtime
Specific problems and implementation
Graphical User Interface FrameworksGUI toolkits use decoration pattern to add functionalities dynamically as explained before.