Command

 
Purpose Encapsulate a request as an object. Enables polymorphic client processing of different requests. Fits naturally into [priority] queue processing, typical of transaction servers (e.g., file servers, web servers). Results in a simple, general interface that is unaffected by new commands/transactions.
Structure
Consequences
  • May be able to extend functionality of Receiver w/o changing its formal interface.
Implementation
  • A powerful, dangerous variation is to pass in a reference of the Receiver to the Command object's execute method. This allows the Command to manipulate the Receiver in new ways, not provided for at the time the Receiver was deployed. Clearly, there are security concerns associated with such power.
  • If concrete commands are declared final, one possible security hole is plugged.
Sample Code
Related Patterns

 cappello@cs.ucsb.edu © Copyright 2010 Peter Cappello                                           2010.04.29