Definition: The command pattern encapsulates tasks as objects. The tasks can be executed with a single method call and then forgotten about.
Usage: Use the command pattern to parameterize objects with different requests, queue or log requests, and support undoable operations.
interface PuzzleGameMove {
do()
undo()
}
The player can select from a variety of moves implementing this interface. Each one can "do" itself. Additionally, it can "undo" itself so that the player can undo his last move. Infinite undo/redo functionality can be implemented with a pair of stacks storing what moves have been done/undone.
Copyright (C) 2008 Steven Fletcher. All rights reserved.