• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Proxy Vs Decorative pattern

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between Proxy pattern and Decorative pattern ?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The intent.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Proxy is a creational pattern, that means, it is used for creating objects.
It is used when creating a new object is costly. In such cases we make a copy of the existing object. See Java Cloneable interface and clone method for more details.

Decorator pattern comes under structural patterns. The decorator pattern helps to add behavior or responsibilities to an object. This is also called �Wrapper�.
 
Ranch Hand
Posts: 196
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Decorator Pattern is also known as the Wrapper pattern.
The purpose of this pattern is to add additional responsibilities to an object. These responsibilities can ofcourse be added through inheritence.
But because of the lack of flexibility a better way is to use composition, aka Wrapping aka the Decorator Pattern.
So the decorator pattern is about adding responsibilities through defining a new class, that wraps the old class, and adds the new responsibilities.

The Proxy Pattern is also known as the Surrogate pattern.
The purpose of this pattern is to add an intermediate between the client and the target object. This intermediate shares the same interface as the target object. The confusing part is that a Proxy also uses composition as the Decorator pattern does. But the proxy pattern doesn't add new responsibilities. It is just a surrogate of the object.

If i didn't make myself clear, please ask for more detail.
 
Your mind is under my control .... your will is now mine .... read this tiny ad
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic