Structural Patterns: Decorator

Decorator pattern provide ways of attaching new state and behavior to an object dynamically.

UML Diagram-

Decorator Design Pattern

Decorator Design Pattern

1. The object being decorated is untouched so it does not know it is being decorated.
2. There is no one big feature-laden class with all the options in it.
3. Decorations are independent of each other.
4. It does not rely on inheritance for extending behavior. Instead it instantiate the object and adds new decorations in it.
5. Decorator pattern does not need any advanced language feature; it rely on object aggregation and interface implementation.
6. Decorators can inherit directly from the component and maintain an object of that class as well.

Use of Decorator pattern-
1. Any Input/ Outbound bound process- like video streaming can be compressed at different rates and sound can be input to a simultaneous translation service. Consider the following hierarchy:


The subclasses decorate Stream because they inherit from it, and they also contain an instance of a stream that is set up when an object is constructed. Many of their properties and methods relate to this instance.
2. Consider desktop browser and a mobile browser, mobile browser creates display object suitable for smaller screen including scroll bars and excluding any banner.
3. Decorator pattern so do useful that they are in .NET 3.0. System.Windows.Controls provides a base class for creation of custom controls.

Use Decorator Pattern when you have-
An Existing component class that may be unavailable for sub-classing.
Use Decorator pattern when you want to-
1. Attach additional state or behavior to an existing object.
2. Make changes to some objects in a class without affecting others.
3. Avoid sub-classing because too many classes could be the result.

6 Responses to Structural Patterns: Decorator

  1. IanWatts says:

    I like the content of your page

  2. Anonymous says:

    Wonderful information. I will spread the word to my friends to tell them to visit your site.

  3. Wow! This might be 1 particular of probably the most useful blogs We have ever arrive across on this topic. Basically Superb.

  4. ErichBerg says:

    Itâ??s really a nice and helpful piece of information. Iâ??m glad that you shared this helpful info with us. Please keep us informed like this. Thanks for sharing.

  5. I loved up to you’ll obtain carried out right here. The comic strip is attractive, your authored subject matter stylish. nonetheless, you command get bought an nervousness over that you want be delivering the following. in poor health certainly come further before again since precisely the similar just about very often inside of case you shield this hike.

  6. Great! thanks for the share!

Leave a Reply