Proxy Pattern: Techniques for Implementing Proxies (I)
Learn how to create a proxy object using composition object literals.
We'll cover the following...
A proxy is an object that controls access to another object, called the subject. The proxy and the subject have an identical interface, and this allows us to swap one for the other transparently; in fact, the alternative name for this pattern is surrogate.
A proxy intercepts all or some of the operations that are meant to be executed on the subject, augmenting or complementing their behavior. The following illustration shows a schematic representation of this pattern:
The above illustration shows us how the proxy and the subject have the same interface, and how this is transparent to the client, who can use one or the other interchangeably. The proxy forwards each operation to the subject, enhancing its behavior with additional preprocessing or postprocessing.
Note: It's important to observe that we’re not talking about proxying between classes; the Proxy pattern ...