Motivation

  • Ordinary C++ statement are perishable
    • Cannot undo a field/property assignment
    • Cannot directly serialize a sequence of actions
  • Want an object that represents an operation
    • X should change its field Y to value Z
    • X should do W()
  • Uses: GUI commands, multi-level undo/redo, macro recording and more!

Info

CommandQuery
Asking for action or changeAsking for information

Summary

  • Encapsulate all details of an operation in a separate object
  • Define instruction for applying the command (either in the command itself, or elsewhere)
  • Optionally define instruction for undo the command
    • Can create composite commands (a.k.a. macros)