A proxy represents another element, provides a surrogate or placeholder for another element, e.g. to control access or add functionality to it.
Some elements (in the figure below it’s called
RealSubject) might be
resource-intensive, overloaded or difficult to enhance.
The proxy (placeholder) provides exactly the same interface as the original object.
In the following figure it’s called
doSomething(). A Consumer needing
doSomething() gets a reference to the
Proxy instead of the
The proxy can control access to the real subject, can cache results or defer calls. No change is needed an the consumer and the real subject.
Security (or protection) Proxy: can be used to control access to a resource.
Remote Proxy: In distributed (object) programming, a local object (proxy) represents a remote object (one that lives in a different address space).
Virtual Proxy: If some resource is expensive in terms of memory, capacity, computing power or similar, a proxy (skeleton) implementation might be helpful sometimes.
Caching Proxy: Stores results that have already been computed by the original object.
- Adapter provides a different interface to its subject. Proxy provides the same interface.