Java Reference
In-Depth Information
Several rules govern the different kinds of proxies.
Remote - The remote proxy is responsible for all the network hassle. It has to marshall (pack) and unmarshall
(unpack) all the arguments sent and received.
Virtual - The real object is very expensive to create, so postpone the creation as long as possible, or perform the
creation a piece at a time, rather than all at once. If the proxy keeps a lot of information for the real subject, you
don't need to instantiate the real object for access to these variables.
Protection - You can use the protection proxy to control who accesses which method, and to give permission on
a method based on the individual caller.
Implementation
The Proxy class diagram is shown in Figure 3.10 .
Figure 3.10. Proxy class diagram
For Proxy, implement the following:
Service - The interface that both the proxy and the real object will implement.
ServiceProxy - ServiceProxy implements Service and forwards method calls to the real object
( ServiceImpl ) when appropriate.
ServiceImpl - The real, full implementation of the interface. This object will be represented by the Proxy
object.
Benefits and Drawbacks
The consequences of this pattern vary considerably depending on the specific type of proxy.
Remote proxy - The remote proxy benefit is that you can hide the network from the client. The client will think
it has a local object that performs the work. In fact it has a local object that sends a request over the network to
get the work done. Don't forget that a potential downside to this is that because you don't realize you're invoking
network behavior, you might not be prepared for the time penalties that result.
Virtual proxy - The great benefit of this proxy is that you have a placeholder to interact with and you don't have
to create the real product until you really need it. Furthermore, it can perform some optimization as to when and
how to create the real object.
Protection proxy - This proxy's benefit is that it will allow access control to be determined.
Pattern Variants
One variant of this pattern is when the proxy does not know the real object other than by its interface. It allows
for greater flexibility, but this works only if the proxy is not responsible for creating and/or destroying the real
object.
Related Patterns
Related patterns include the following:
 
Search WWH ::




Custom Search