Proxy pattern

The Proxy pattern provides an intermediary object that redirect requests to the another real object. Why we need an intermediary object, when we can work directly with real object? Answer is:

  • to control creation of expensive object. This type of proxy is known as virtual proxy and is used for lazy initialization.
  • to control connection to the remote object. This type of proxy is known as remote proxy.
  • to control access to the real object, is client has permission and etc. This type of proxy is known as protective proxy.

In conclusion, we can see, that proxy has same interface as real object, but does additional stuff before redirect request to the real object.

proxy vs adapter vs decorator

  • adapter provides different interface to the real object
  • decorator provides an extended interface with additionaly or modified functionality