Intent
Provide an abstract definition for a method or a class and redefine its behavior later or on the fly without changing its structure.
Where to use & benefits
- To make many similar operations template.
- From many specialized operations to a generalized operation.
- Refactor common behavior to simplify code.
- Algorithm related improvement.
- Need good coding skill to conquer it.
- May be hard to read for novice.
- Easy to produce ambiguity if not written well.
Structure

Participants
AbstractClass (ShapeDecorator)
defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm and implements a template method defining the skeleton of an algorithm. The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects.
ConcreteClass (ColorDecorator)
implements the primitive operations ot carry out subclass-specific steps of the algorithm
Example
In the demonstration application, ShapeDecorator class allows the subclass ColorDecorator to define the decorateShape operation, which is used to decorate the shape. But other operations like drawing shape, etc. are carried out by the ShapeDecorator class.