The Proxy pattern supports objects that control the creation of and access to other objects. The proxy is often a small (public) object that stands in for a more complex (private) object that is activated once certain circumstances are clear.
Kind of Proxies and there features-
There are several kinds of proxies, the most common of which are:
Virtual proxies- Hands the creation of an object over to another object (useful if the creation process might be slow or might prove unnecessary)
Authentication proxies- Checks that the access permissions for a request are correct
Remote proxies- Encodes requests and send them across a network
Smart proxies- Adds to or change requests before sending them on
With regard to a social networking system, these map as follows:
â?¢ Delaying the creation of a rich environment (virtual proxy)
â?¢ Logging in users (authentication proxy)
â?¢ Sending requests across the network (remote proxy)
â?¢ Performing actions on friendsâ?? books (smart proxy)
Use of Proxy pattern-
Proxies are front-ends to classes that have sensitive data or slow operations. They are often found in image-drawing systems, where the proxy places a placeholder on the screen and then activates a real drawer to fetch and render the image. In the same way, they can be involved in initiating the buffering associated with video streaming.
Proxies, like decorators, forward requests on to another object. The difference is that the proxy relationship is set up at design time and is well-known in advance, even though the Subject is not an active participator in the relationship. Decorators, on the other hand, can be added dynamically.
Use the Proxy pattern when you have objects that-
â?¢ Are expensive to create.
â?¢ Need access control.
â?¢ Access remote sites.
â?¢ Need to perform some action whenever they are accessed.
Use the Proxy pattern when you want to-
â?¢ Create objects only when their operations are requested.
â?¢ Perform checks or housekeeping on objects whenever accessed.
â?¢ Have a local object that will refer to a remote object.
â?¢ Implement access rights on objects as their operations are requested.