Responsive Ads Here

Tuesday, July 30, 2013

Decorator Pattern

Home

Decorator Pattern


Intent



  • The intent of this pattern is to add additional responsibilities dynamically to an object.


Implementation


The figure below shows a UML class diagram for the Decorator Pattern:




 The participants classes in the decorator pattern are:

  • Component - Interface for objects that can have responsibilities added to them dynamically.
  • ConcreteComponent - Defines an object to which additional responsibilities can be added.
  • Decorator - Maintains a reference to a Component object and defines an interface that conforms to Component's interface.
  • Concrete Decorators - Concrete Decorators extend the functionality of the component by adding state or adding behavior.


Description


The 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.

Home

No comments:

Post a Comment