Proxy
Intent
Provide
a surrogate or placeholder for another object to control access to it.
-Design Patterns, GoF
A
friend of mine -- a medical doctor, no less -- once told me that he convinced a
friend to take a college exam for him. Someone who takes the place of someone
else is known as a proxy.
Unfortunately for my friend, his proxy drank a bit too much the night before
and failed the test. – JavaWorld.com, Feb 2002
Also Known As
Surrogate
Questions
1)
What are the motivations behind using the following types of proxies?
·
Virtual
Proxy
·
Remote
Proxy
·
Protection
Proxy
·
Smart
Reference
2)
What is the difference between an Adapter and a Proxy?
3)
If considering a virtual proxy, what would you need to sway your decision in
favor of its use? In other words, what
data or requirements artifacts would be necessary before the additional
complexity of a Proxy was incurred?
4)
When are the real objects (behind the Proxy) created?
5) Does
the client ever reference the real thing?
i.e. why not use just basic delegation?
6)
Could you use basic inheritance and accomplish the same thing (i.e. the Proxy
extends the real thing)? Why or why
would you not want to do that?
7)
Should you create a Proxy if there are many methods in the interface? Or if the interface is not
stable?
Examples – Which are Proxies?
1)
2)
3)
Swing’s ImageIcon and ImageIconProxy.
4) java.lang.reflect.Proxy.
-What type of proxy is this?
-Why would you want to use?
-Should it’s
conceptual weight discourage use?
References
·
Dynamic
Proxy for Local and Remote Interface (EJB 2.0), Kjetile
Helle (TheServerSide.com, August 2001)
·
Take
Control with the Proxy Design Pattern, David Geary (JavaWorld.com, February 2002)