Proxy Pattern

(from Design Patterns)

Synopsis

Provide a surrogate or placeholder for another object which cannot be accessed by normal means.

Context

You want a normally inaccessible or unavailable object to appear like an ordinary object. For example, the object might be:

Forces

Solution

Make a Proxy object with the same interface as the subject and which holds a reference to the subject. This is usually not a conventional reference, but may be a

The Proxy may forward requests to the subject or simply replace itself by the subject, depending on the Proxy's purpose.

This solution looks like a Decorator and may be implemented by identical means but it is not accompanied by the same policy. A Decorator adds capabilities to an object; a Proxy is a bridge to an inaccessible object. Since a Proxy is not an addition to the object it stands for, there is no need for delegation as in the Decorator pattern. (However, there is still a use for the hot swap technique.)

Consequences

Implementation

See Design Patterns for sample code.

Known Uses


Thomas Minka
Last modified: Mon Jan 20 17:14:18 EST 1997