----

Friday, September 13, 2013

Proxy Design Pattern Example

Proxy Design Pattern: 

Proxy Design Pattern addresses a problem where access to real object needs to be controlled in a manner by which only authorized user can access the real object. Proxy pattern can also be applied to allow only limited access to real object.

Let’s take an example of banking system

Bank as a whole, is a very secure system, the access to which is restricted only to customers who holds an account with the bank. The access to the bank is controlled by bank personal such that if a bank customer wants to perform a transaction, then he will not be allowed to do so. The bank personal ensures that only customer who holds account with the bank is allowed to perform transaction.

The bank personal is in fact the proxy who controls access to the bank to the outside world. This proxy validates the authenticity of the customer before performing any transaction, on behalf of the bank.

If we have a class Bank which represents real Bank then we need to expose this Bank object to the client directly, so without proxy any non-bank client who has a valid account number can perform transaction with the Bank object which is not desirable.



No comments :

Post a Comment