Proxy Design Pattern - a real time case study example

Proxy Design Pattern - A Real Time Example Study


Introduction

  • In proxy pattern, a class represents functionality of another class. This type of design pattern comes under structural pattern. In proxy pattern, we create object having original object to interface its functionality to outer world.
  • Consider the following diagram where an Image interface is created and concrete classes implementing the Image interface. ProxyImage is a a proxy class to reduce memory footprint of RealImage object loading. ProxyPatternDemo will use ProxyImage to get an Imageobject to load and display as it needs. 

ProxyImage Diagram Representation

Proxy Pattern Example Class Diagram

Real Time Scenario Explanation:

user 'Iavshali' wants to know the address of user 'Vivek'. Based on the user 'Vivek's' grant access, the address is either shared or not shared


Note:

There are 2 companies. Company A(OriginalDesignPattern Class in the attached java file below) & Company B(ProxyDesignPattern Class in the attached java file below)
  • Company A maintains the user information that includes username, password and user_address
  • Company B is medium between user_address requesting user (here user 'Iavshali') and Company A
  • Company A is medium between Company B and the request granting user (here user 'Vivek')

Consider the following steps:

Step 1: 'Iavshali' requests 'Vivek' to reveal his address via Company B
Step 2: Company B contacts Company A to request user 'Vivek' to grant access
Step 3: Company A contacts the user 'Vivek' and he can either accept or reject the request
Step 4: Company A responds back user 'Vivek's' sharing status to Company B
Step 5: Based on the results from Company A, Company B shows the results to user 'Iavshali'

Now, download the file using the link below.
click here to download 'ProxyDesignPattern.java' file
(use IDEs like Eclipse, etc to open this file and run it)

View the inlined comment at each code to understand how the code works. After the successful execution of it, 2 cases obtained.


Positive Case: 
User Vivek grants permission
Address of user: Vivek
45, Ver Terr, New York

Negative Case: 
User Vivek did not grant access permission
Request Status: DENIED


Inference:
In both of above cases, the password of the user 'Vivek' was never revealed... 
Thats the awesomeness of using proxy design pattern

Thanks for your time reading my blog.
Have a great day.


Contact Info: techengineervivekvells@gmail.com / techengineervivek@gmail.com
Check out :
my google+ acc: Vivek Vellaiyappan Google+
youtube acc: Vivek Vellaiyappan Youtube

Comments