Thursday 24 April 2014

Proxy DesignPattern

What Is PROXY?


  • Someone who takes the place of someone else is known as a proxy.
  • In Proxy pattern, a class represents functionality of another class. This type of design pattern comes under structural pattern.
  • Proxy design pattern allows you to create a wrapper class over real object. Wrapper class which is proxy, controls access to real object so in turn you can add extra functionalities to real object without changing real object's code.


  • Example:
  1. If a Person has account in a bank and he want to withdraw some 5000 from bank.If it is direct process ,He has to go to bank and fill the withdraw form and the employee check for the account balance and then process the withdraw request.
  2. Second Process:,the Person directly go to an ATM and enter pin and amount ,the machine checks the account details and send info to bank .and process the request.Here ATM is not the Real bank or real object to work on.
When?

Proxy is required whenever there is need for more sophisticated or versatile reference to an object than a simple pointer. Here are some situations when proxy pattern is applicable.

  1. remote proxy provides a local representative for an object in a different address space providing interface for remote resources such as web service or REST resources.
  2. virtual proxy creates expensive object on demand.
  3. protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.
  4. smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed.
  5. Adding a thread-safe feature to an existing class without changing the existing class's code.

How??


will update soon...


                 


No comments:

Post a Comment

test