Tuesday, 19 April 2016

Command pattern - Behavioral


  • Provides an interface to encapsulate a request 
    • Allows the parameterization of clients with different requests
    • Allows saving the requests in a queue
  • Make the interface implemented by subclasses in order to parameterize the clients.


 


How it works ?
  • Both an invoker object and several command objects are held by a client object.
  • Client knows which command to run.
  • Command invokes a method of reciever
  • Invoker object knows how to execute a command.
  • To execute a command, it passes the command object to the invoker object.


Where to use ?
  • One action can be represented in many ways, like drop-down menu, buttons and popup menu.
  • Specify and execute the request at different time.
  • Decouple the object with its trigger
  • Easily to be extensible without touching the old structure.

No comments:

Post a Comment

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