Tuesday, 19 April 2016

Proxy pattern - Structural



  • Use a simple object to represent a complex one
  • provides a "Placeholder" for an object to control references to it 
  • A class represents functionality of another class
  • Creates object having original object to interface its functionality
       
     


Where to use ?
  • If creating an object is too expensive in time or memory
  • Postpone the creation until you need the actual object
  • Load a large image (time consuming)
  • Load a remote object over network during peak periods
  • Access right is required to a complex system


Implementation example

Concrete class BankAccount implementing interface Account
BankAccount fetching details from banking system

Another class ProxyAccount also implementing same interface Account
ProxyAccount maintaining an object of BankAccount , and returning, if already loaded.
If it doesn’t exists, create BankAccount (real) object which is maintained.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.