Ghajini Johnson wrote:kentkaj
Can you be more specific....
Decorator is not for adding additional responsibilities.
Quoted from Design Patterns [GoF].
Decorator
Intent
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing
for extending functionality.
We can use subclassing, but if we have many options to combine, we'll end up with too many classes.
When call a Decorator's operation, it will call wrapped component's operation *and* may call additional operations.
Proxy
Intent
Provide a surrogate or placeholder for another object to control access to it.
If looking at structural, implementations of Decorator and Proxy are similar, but their purposes are different.
By definition Proxy will not add additional responsibilities, it will control access, for example, remote proxy, virtual proxy (lazy loading), protection proxy (check access rights).
If a Proxy also add responsibilities, we can say that it's also a Decorator.
SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional