Proxy
Definition
Provide a surrogate or placeholder for another object to control access to it.
Class Diagram
Participants
-
Proxy
- maintains a reference that lets the proxy access the real subject.
- provides an interface identical to Subject's so that a proxy can be substituded for the real subject.
- controls access to the real subject and may be responsible for creating and deleting it.
-
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.
Benefits
- A remote proxy can hide the fact that an object resides in a different address space.
- A virtual proxy can perform optimizations such as creating an object on demand.
- both protection proxies and smart references allow additional housekeeping tasks when an object is accessed.
Usage
- when you need a more versatile or sophisticated reference to an object than a simple pointer.