Proxy Design Pattern
A proxy is a surrogate class for the target object. If a method call has to be invoked
in the target object, it happens indirectly through the proxy object. The feature which
makes proxy ideal for many situations is that the client or the caller is not aware that
it is dealing with the proxy object. The proxy class is shown in the following figure:
In the above figure, when a client invokes a method target towards the Target
service, the proxy intercepts the call in between. The proxy also expose a similar
interface to the target, hence the client is unaware of the dealing with the proxy.
Thus the proxy method is invoked. The proxy then delegates the call to the actual
target since it cannot provide the actual functionality. When doing so, the proxy can
provide call management towards the actual method. The entire dynamics is shown
in the following figure:
ProxyService TargetService
+fx() +fx()
Client uses>
<
> <>
+fx()
<>
?????? ?????? interface
IService
Chapter 13
[ 239 ]
A proxy is usually implemented by using a common, shared interface or super class.
Pages:
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331