Design Pattern
  • Introduction
  • What is singleton?
  • factory method design pattern
  • loose coupling VS tight coupling
  • Proxy pattern
  • abstracFactory
  • OOA & OOD
  • Decorator Design Pattern
  • Iterator Design Pattern
  • The Observer Pattern
  • Spring Singleton VS Java Singleton
Powered by GitBook
On this page
  • Proxy design pattern:
  • Would I use this pattern?

Was this helpful?

Proxy pattern

Previousloose coupling VS tight couplingNextabstracFactory

Last updated 5 years ago

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.

Proxy design pattern:

  1. Create a "wrapper" for a remote, or expensive, or sensitive target

  2. Encapsulate the complexity/overhead of the target in the wrapper

  3. The client deals with the wrapper

  4. The wrapper delegates to the target

  5. To support plug-compatibility of wrapper and target, create an interface

Would I use this pattern?

  • 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.