I've noticed that on all the examples that illustrate the decorator pattern, there is a base class/interface and there is a decorator class that inherits/implements it, after which, all the decorated classes extend the decorator class. Something along the following lines :
Interface Window > WindowDecorator > WindowDecorator > VerticalScrollBarDecorator
the above hierarchy was taken from Wikipedia's Design Pattern Page.
The thing is, I want decorate some "Operation" classes, and have something along the following hierarchy :
root class is Operation
decorated classes could be Operation1, Operation2, and so forth.
I would have a constructor taking an Operation object in my Operation class, like this :
public Operation(Operation op)
{
this.op = op;
}
an abstract method ( let's call it doOperation ) that performs the operation ( and which each subclass overrides ) and another method that calls the "stored" object's doOperation, like this ( located in the base class ):
public void executeOperation(some_args_here)
{
if(op != null)
op.doOperation(); // call stored object's doOperation first
doOperation(); //execute this operation
}
The thing is, I don't really see the need for a OperationDecorator class here, when I can do everything a OperationDecorator class would do right in the base class. Am I misusing the decorator pattern if I use it like this? Am I missing out on some of it's features?