View Source on Github

Proxy

Difficulty-Beginner Gang Of Four Java Structural

Also known as

Surrogate

Intent

Provide a surrogate or placeholder for another object to control access to it.

alt text

Applicability

Proxy is applicable whenever there is a need for a more versatile or sophisticated reference to an object than a simple pointer. Here are several common situations in which the Proxy pattern is applicable

  • Remote proxy provides a local representative for an object in a different address space.
  • Virtual proxy creates expensive objects on demand.
  • Protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.

Typical Use Case

  • Control access to another object
  • Lazy initialization
  • Implement logging
  • Facilitate network connection
  • Count references to an object

Tutorials

Presentations

Real world examples

Credits