I am here to continue the discussion around Design Patterns. Today, we will go through one of the structural design patterns called Proxy.
Also in case you have not had a look at our previous articles, go through the following links:
- Design Patterns Simplified: Part 1 (Introduction)
- Design Patterns Simplified - Part 2 (Singleton)
- Design Patterns Simplified - Part 3 (Simple Factory)
- Design Patterns Simplified - Part 4 (Abstract Factory)
- Design Patterns Simplified - Part 5 (Factory Method)
- Design Patterns Simplified - Part 6 (Prototype)
- Design Patterns Simplified - Part 7 (Builder)
- Design Patterns Simplified - Part 8 (Facade)
- Design Patterns Simplified - Part 9 (Adapter)
- Design Patterns Simplified - Part 10 (Decorator)
- Design Patterns Simplified - Part 11 (Bridge)
- Design Patterns Simplified - Part 12 (Composite)
Before talking about its implementation let’s begin with defining it.
As per GOF guys, Proxy pattern is defined as follows.
“Provide a surrogate or placeholder for another object to control access to it.”
Well! Let’s understand what they mean and where this pattern can be fit into.
As the name suggests, proxy pattern is used to provide proxy or surrogate object in order to access actual object. Surrogate object typically sits in local machine and mimics the actual object which may be part of another application or domain or sitting in remote servers.
By having surrogate object in a local machine, the implementation details to connect to actual objects are abstracted and that lead to clean design.
Remember creating service references or web references to connect to WCF or Web Service? This also creates proxy objects behind the scene and mimics to client as original object.
Now let’s see the UML of proxy pattern.

Proxy pattern has three key elements as following.
- Subject: This is an interface which will be implemented by both RealSubject and Proxy.
- RealSubject: This is an actual class that implements Subject interface members.
- Proxy: This is class which sits in local machine to mimic the real object (i.e. RealSubject). It keeps the reference of RealSubject in order to access its members.
How Proxy pattern works?
We will understand this by simple example.
Let’s take an example of a stock price web service. There are lot of paid and free web services available today to provide stock quotes. Here we will try to mimic the same.
Let’s start with creating Subject interface as following.


Prakash TripathiPosted May 3, 2016, 10:32 AM
Thnx Amit.
Amit DavePosted May 3, 2016, 10:27 AM
Keep up the Good work!
Prakash TripathiPosted May 3, 2016, 2:01 AM
Thnx Thiruppathi.
Thiruppathi RPosted May 3, 2016, 1:51 AM
Superb..
Prakash TripathiPosted May 2, 2016, 11:31 PM
Thnx Bhavik.
Bhavik PatelPosted May 2, 2016, 10:23 PM
another good shot
Prakash TripathiPosted May 2, 2016, 12:18 PM
Thnx Vignesh.
Prakash TripathiPosted May 2, 2016, 12:17 PM
Thnx Mahendra.
Vignesh ManiPosted May 2, 2016, 12:01 PM
nice
Vignesh ManiPosted May 2, 2016, 12:01 PM
Nice one
Mahendra SinghPosted May 2, 2016, 11:57 AM
keep it up
Prakash TripathiPosted May 2, 2016, 10:56 AM
Thnx Debasis.
Debasis SahaPosted May 2, 2016, 10:10 AM
Nice One..