This what I've found in the GoF "Design Patterns" :
The decorator conforms to the interface of the component it decorates so that its presence is transparant to the components clients. The decorator forwards requests to the component ...
So basically after having decorated my component, I want my component itself to become the decorated version.
Code:
class Component {
public:
Component() {}
};
class Decorator : public Component {
public:
Decorator(Component const& p_comp) : _comp(p_comp) {}
protected:
Component _comp;
};
class BooDecorator_one : public Decorator {
public:
BooDecorator(Component const& p_comp) : Decorator(p_comp) {}
void boo() { ... }
};
I do not want to modify all existing functions which take an object of "Component" as argument, so I would like to do something like this :
Code:
int main()
{
Component myComponent;
BooDecorator myDecoratedComponent(myComponent);
myComponent.boo();
return 0;
}
which will of course fail since "boo()" is not a function of "Component" . But isn't this what the GoF ment by the citation?
Something like
Code:
myComponent = myDecoratedComponent;
seems odd to me.
Has anyone an idea or solution for what I want? Thanks a lot !!
Mark