Proxy Pattern

The intent of Proxy Pattern is to provide a placeholder for an object to control access to it, and add a wrapper and delegation to protect the real component from undue complexity.

The reason to need the placeholder is sometimes we want to control the access to the target object due to different reasons, such as
1) it is expensive to create an object
2) giving different access rights to an object
3) access remote object

Here is the basic flow of proxy pattern:

  • Create a proxy for a target
  • Encapsulate the complexity/overhead of the target in the proxy
  • The client deals with the proxy, and the proxy delegates the request to the target

Implementation

The figure below shows a UML class diagram for Proxy Pattern
Proxy

A proxy client obtains a reference to a proxy (ProxySubject), the client then handles the proxy in the same way it handles RealSubject and thus invoking the method operation(). In ProxySubject operation method can add different logic to control if it invokes RealSubject operation method.

Step 1: create a subject interface

Step 2: create RealSubject class

Step 3: create a Proxy class

Step 4: create a client

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

One thought on “Proxy Pattern

  1. Pingback: Software Design Patterns

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">