F.Proxy Pattern

  1. Summary

    1. Allow creation of placeholder objects.

      1. The intent of this pattern is to provide a Placeholder for an object to control references to it.

      2. Also used as access control and resource sharing mechanism

      3. Well established mechanism for RMI and Web Service implementation.

  2. Overview Tutorials

  1. Example

      1. Internet proxy

      2. Web Service Proxy Object

      3. AOP Proxies.

  1. Proxy Types

    1. Virtual Proxies:

      1. It is used to delay the creation and initialization of expensive objects until needed,

        1. For example: when the “DoSomething” method is invoked.

    2. Remote Proxies:

      1. It provides a local representation of an object that exists in a different address space.

        1. A common example is Java RMI stub objects. The stub object acts as a proxy where invoking methods on the stub would cause the stub to communicate and invoke methods on a remote object (called skeleton) found on a different machine.

    1. Protection Proxies:

        1. Theres are used to controls access to RealSubject methods, by giving access to some objects while denying access to others. A good example is Internet proxy.

    1. Smart References:

        1. They hold references of actual subject and provide a sophisticated access to them such as tracking the number of references to an object.COM Class references are an example of the same.

    1. AOP proxy

      1. Instance Proxy use for Instance Interception by AOP frameworks

      2. Type Proxy Use for Type interception by AOP framewotks

      3. Transparent Proxy (Unity) : Mostly used by AOP frameworks and works as interceptors or like remote proxies

    1. Proxy Type By Creation

        1. Static Proxy : Created during compile time

        2. Dynamic Proxy : Created using reflection at run time

  1. Specific Considerations

    1. Proxy Vs Adapter Design Pattern

        1. The adapter implements a different interface to the object it adapts where a proxy implements the same interface as its subject.

    2. Proxy Vs Decorator Design Pattern

      1. A decorator implementation can be the same as the proxy however a decorator adds responsibilities to an object while a proxy controls access to it.

  1. Related Concepts

    1. AOP : A programming pattern that uses proxy for several purpose

    2. Weaving is a technique that is used to implement and bind proxies by AOP frameworks There are two fundamental type of Weaving

      • Compile-Time Weaving: the program is modified during the build process on the development machine, before deployment.

      • Runtime Weaving: the program is modified during its execution, after deployment.

  1. Related Pattern

    1. Interceptor Pattern : Instance and type proxies are used to implement interceptors that is actually core building block of AOP.

    2. Fly Weight Pattern : In situations where multiple copies of a complex object must exist, the proxy pattern can be adapted to incorporate theflyweight pattern in order to reduce the application's memory footprint. Typically, one instance of the complex object and multiple proxy objects are created, all of which contain a reference to the single original complex object.