Home  /  Questions  /  Question

50   50
Sep 20, 2010

Question on Decorator Pattern

I am not clear why we require to have both an Is-a and a Has-a relationship  between Decorator and Component classes. 

We can just have an Is-a relation and class Component class method using Base::Operation().

 1 comment
A decorator Is-a Component (inherits from the component) so that it can be used anywhere a component can (method calls etc..) A decorator Has-a Component (has a composed instance-reference) so that a particular decorator may wrap a particular component (or other decorator) instance and act as a proxy which adds behavior. --- Lee Eeeee  Mar 26, 2011

1,128   99.9
Sep 22, 2010

Could you post an example implementation on your thoughts of the Decorator pattern so that
I can see how you're thinking? Because I have a hard time seing how it can be accomplished
with a IsA relation only.