Proxy pattern
Last updated
Was this helpful?
Last updated
Was this helpful?
Provide a surrogate or placeholder for another object to control access to it.
A Proxy can also be defined as a surrogate. In the real world, a cheque or credit card is a proxy for what is in our bank account. It can be used in place of cash, which is what is needed, and provides a means of accessing that cash when required. And that's exactly what the Proxy pattern does - controls and manage access to the object they are "protecting".
The Proxy is known as a structural pattern, as it's used to form large object structures across many disparate objects. The definition of Proxy provided in the original Gang of Four book on DesignPatterns states:
Allows for object level access control by acting as a pass through entity or a placeholder object.
Create a "wrapper" for a remote, or expensive, or sensitive target
Encapsulate the complexity/overhead of the target in the wrapper
The client deals with the wrapper
The wrapper delegates to the target
To support plug-compatibility of wrapper and target, create an interface
The object being represented is external to the system
Objects need to be created on demand
Access control for the original object is required
Added functionality is required when an object is accessed.