As I understood both Adapter and Proxy patterns make two distinct/different classes/objects compatible with each for communication. And both of them are Structural patterns. I am getting that both of them are pretty much similar with each other.
Can some one explain what exactly make(s) them different?
EDIT: I went through this question. But I'd rather like to have a close comparison between Adapter and Proxy.
The main differences between Adapter and Proxy patterns are:While proxy provides the same interface, Adapter provides a different interface that's compatible with its client. Adapter pattern is used after the application components are designed so that we can use them without modifying the source code.
Adapter changes the interface of an existing object, while Decorator enhances an object without changing its interface.
The proxy pattern is where one object acts as an interface to another object. The difference between proxy and facade patterns are that we can proxies create interfaces for one object. But facades can be interfaces for anything. We use the proxy to call both foo and bar in obj .
In software engineering, the adapter pattern is a software design pattern (also known as wrapper, an alternative naming shared with the decorator pattern) that allows the interface of an existing class to be used as another interface.
Adapter:
UML diagram:
You can find more details about this pattern with working code example in this SE post:
Difference between Bridge pattern and Adapter pattern
Proxy:
Proxy provide a surrogate or place holder for another object to control access to it.
UML diagram:
There are common situations in which the Proxy pattern is applicable.
For working code, have a look at tutorialspoint article on Proxy.
Key differences:
You can find more details about these patterns in sourcemaking articles of proxy and adapter articles.
Other useful articles: proxy by dzone
From here:
Adapter provides a different interface to its subject. Proxy provides the same interface.
You might think of an Adapter as something that should make one thing fit to another that is incompatible if connected directly. When you travel abroad, for example, and need an electrical outlet adapter.
Now a Proxy is an object of the same interface, and possibly the same base class (or a subclass). It only "pretends" to be (and behaves like) the actual object, but instead forwards the actual behavior (calculations, processing, data access, etc.) to an underlying, referenced object.
Extrapolating to the electrical analogy, it would be OK that the use of an adapter is visible to the client - that is, the client "knows" an adapter is being used - while the use of a proxy might more often be hidden, or "transparent" - the client thinks an actual object is being used, but it is only a proxy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With