It seems that there are similarities between Proxy and Adapter pattern?
Can any one please explain what are the differences? Why we require both of them? In which problems we should use only proxy and NOT another by an .net example?
Thank you
It seems that there are similarities between Proxy and Adapter pattern?
Can any one please explain what are the differences? Why we require both of them? In which problems we should use only proxy and NOT another by an .net example?
Thank you
Proxies are typically used for the following scenarios:
Adaptors play another role - they bridge the gap between two classes that have no relation. The Adaptor can act as both objects. This is used primarily when one has to integrate with legacy systems (or 3rd party frameworks for that matter) where it is not possible to alter the API.
Hope this helps!
A proxy exposes the exact same behavior as the object it hides. A proxy is typically used to contact a remote object without having to know how to contact it. An example is a WCF service, you can encapsulate accessing the service in a proxy that exposes the exact same interface as the wcf service, but hides the implementation details away like using a channelfactory and handling faultexceptions etc... It's like you client is talking to the WCF service locally.
An adapter also hides an underlying object, but it transforms the data you exchange with it to the right format and content used by the underlying object. An example is indeed a legacy system, like Goblin says. You encapsulate the complexity of talking to the legacy system (maybe it uses a chatty or CRUDy API and you want to hide it behind a coarse-grained operation) into an adapter to prvide a simple way of talking to the legacy system to your clients.
That's how I understand it at least.
EDIT: by the way, I personally feel that you don't have to see design pattern names as the end-all-do-all. Choose the right pattern based on what you want to achieve and call it whatever you want.