Wednesday, October 28, 2015

Proxy pattern

Proxy pattern provides a surrogate or placeholder for another object to control access to it. It adds a wrapper and delegation to protect the real component from undue complexity.


A check or bank draft is a proxy for funds in an account. A check can be used in place of cash for making purchases and ultimately controls access to cash in the issuer's account.

Check list

  1. Identify the leverage or "aspect" that is best implemented as a wrapper or surrogate.
  2. Define an interface that will make the proxy and the original component interchangeable.
  3. Consider defining a Factory that can encapsulate the decision of whether a proxy or original object is desirable.
  4. The wrapper class holds a pointer to the real class and implements the interface.
  5. The pointer may be initialized at construction, or on first use.
  6. Each wrapper method contributes its leverage, and delegates to the wrappee object.

0 comments:

Post a Comment