Proxy Design Pattern
The Proxy design motif
The informal description: Excerpts from [Gamma et al. 1995] (adapted for
Intent: Provide a surrogate or placeholder for another object to control access to it.
Structure: Original OMT diagram converted to UML (Why
- Maintains a reference that lets the proxy access the real subject. Proxy may refer to a Subject if the RealSubject and Subject interfaces are the same.
- Provides an interface identical to Subject's so that a proxy can by substituted for the real subject.
- Controls access to the real subject and may be responsible for creating and deleting it.
- Other responsibilities depend on the kind of proxy:
- Remote proxies are responsible for encoding a request and its arguments and for sending the encoded request to the real subject in a different address space.
- Virtual proxies may cache additional information about the real subject so that they can postpone accessing it. For example, the ImageProxy from the Motivation caches the real image's extent.
- Protection proxies check that the caller has the access permissions required to perform a request.
- Subject: defines the common interface for RealSubject and Proxy so that a Proxy can be used anywhere a RealSubject is expected.
- RealSubject: defines the real object that the proxy represents.
Collaborations: Proxy forwards requests to RealSubject when appropriate, depending on the kind of proxy.