next up previous contents
Next: Mediator Up: Patterns Used Previous: Patterns Used

Command

The command pattern encapsulates a request as an object [7]. Essentially, this pattern creates an abstraction for an action that is to be taken. In the context of this work, whenever a widget changes value, it invokes its command object. The abstraction allows the widget to be bound to a particular action by instantiating the appropriate command object at run-time.

  figure179
Figure 6.3: Partial diagram of Command pattern. Concrete commands invoke methods on Application.

Invoking a command object form within a pjrWidget method:

  this->command->Execute(this);

The instance of pjrWidget passes a reference to itself to the command. This allows the command to get information about the state of the widget that invoked the command. The command object also keeps a reference to the Application component. It can get information from the application and together with the information from the widget, invoke a method in the Application component, changing the application's state.



Paul John Rajlich
Mon May 4 16:53:57 CDT 1998