- 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.
- Proxies are interfaces to classes that have sensitive data or slow operations.
Different Types of Proxies
- Hands the creation of an object over to another object.
- Useful if the creation process might be slow or might prove unnecessary.
- Checks that the access permissions for a request are correct.
- Encodes requests and sends them across a network.
- Adds to or changes requests before sending them on.
Class diagram: (see Proxy Pattern code review)
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.