- The Proxy Pattern
Intent
Provide a surrogate or placeholder for another object to control access to it
A proxy is
› a person authorized to act for another person
› an agent or substitute
› the authority to act for another
There are situations in which a client does not or can not reference an
object directly, but wants to still interact with the object
A proxy object can act as the intermediary between the client and the target
object
http://userpages.umbc.edu/~tarr/dp/lectures/Proxy.pdf
- Intent
Provide a surrogate or placeholder for another object to control access to it.
Use an extra level of indirection to support distributed, controlled, or intelligent access.
Add a wrapper and delegation to protect the real component from undue complexity.
Problem
You need to support resource-hungry objects, and you do not want to instantiate such objects unless and until they are actually requested by the client.
Example
The Proxy provides a surrogate or place holder to provide access to an object. A check or bank draft is a proxy for funds in an account. A check can be used in place of cash for making purchases and ultimately controls access to cash in the issuer’s account.
Rules of thumb
Adapter provides a different interface to its subject. Proxy provides the same interface. Decorator provides an enhanced interface.
Decorator and Proxy have different purposes but similar structures. Both describe how to provide a level of indirection to another object, and the implementations keep a reference to the object to which they forward requests.
http://sourcemaking.com/design_patterns/proxy
- Proxy pattern
A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate.
http://en.wikipedia.org/wiki/Proxy_pattern
No comments:
Post a Comment