We use this Pattern when we require don't want to give a direct access to object under some scenario and rather offer a surrogate object or proxy object which provides the functionality in place of the real object.
There could be several scenario where we would want this kind of functionality.
There could be several scenario where we would want this kind of functionality.
- The real object has some sensitive operation which would be risky to expose.
- The real object creation is memory extensive so we want to control the behavior of its creation.
- The real object is remotely located and rather we want to interact through a local copy using proxy which is actually aware of it location.
So lets look at the UML diagram of the same.
So here we have Subject interface which is implemented by both the Proxy and RealObject and proxy object has reference to the real object , now the client will instantiate Proxy object to perform some action and , proxy object will delegate the call to RealSubject to perform the same.
Comments
Post a Comment