• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

what is the difference between decorator and proxy

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What is the difference between decorator and proxy?

Both are looking like similar..
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hm, what is the similarity? For me, they are quite different.

Decorator is for enhancement (as the name guide), Proxy is for ... well proxy, it can help to improve performance like lazy loading, control access, hiding remoteness.
 
Ghajini Johnson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please look at the class diagram and then you can see the similaties.

Definitions are absolutely different. Nothing to worry in the defintions......

The aggregation in decorator is pointing to the target abstraction.. where as the proxy is having the similar aggregation to the concrete class. No much difference.. Both are adding additional functionality..

See Mikalai Zaikin's book for patterns..

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.io is built on decorator pattern. InputStream, BufferedInputStream. At runtime
an object is given additional responsibility

Ejb container uses proxy pattern where EjbObject(proxy) from server interacts with the Enterprise beans and adds additional responsibilites like security, concurrency and ejb feautures on the enterprise bean

Hope this helps
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ghajini Johnson wrote:Please look at the class diagram and then you can see the similaties.

Definitions are absolutely different. Nothing to worry in the defintions......


I think you've already answered your own question. That is the different you have been looking for.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

aleem khan wrote:java.io is built on decorator pattern. InputStream, BufferedInputStream. At runtime
an object is given additional responsibility

Ejb container uses proxy pattern where EjbObject(proxy) from server interacts with the Enterprise beans and adds additional responsibilites like security, concurrency and ejb feautures on the enterprise bean

Hope this helps


From definition, adding responsibilities is the purpose of Decorator pattern.
I'm not sure about EJB container, maybe it uses both Proxy and Decorator patterns.
 
Ghajini Johnson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kentkaj

Can you be more specific....

Decorator is not for adding additional responsibilities. It is the alternative to subclassing. You can even override also..

Same capabilities are there in Proxy also, so I am asking where does that finer difference comes in.

Again, please let me know if you understand it, otherwise, thank you...
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic