The Dispatcher's Undo Button
The dispatcher assigns packages to drivers all day, and needs to undo a mistake, and redo it.
Updated
An Action You Can Hold
- Command: An Action You Can Hold (Journeyman): When the dispatcher's plan for the morning is stored as rows of text and run by a switch on each action's name, every new kind of action means editing the runner; the Command pattern turns "Assign package 42 to Dana" into an object that can be stored, queued, logged and run later.
- Undo and Redo with Commands (Journeyman): An undo button that remembers only the last change can't take back two mistakes, and can't redo anything; when each command knows how to reverse itself, a stack of done commands and a stack of undone ones give the dispatcher as many undos and redos as she needs.
Look-Alikes
- Look-Alikes: Strategy, State and Command (Journeyman): Strategy, State and Command have the same class diagram: a promise, a few classes that keep it, and an object that holds one; what tells them apart is who picks the object, whether it changes itself, and whether it can be stored and undone, and picking the wrong one puts a decision in the wrong place.
Exercise: The Dispatch Board
- Exercise: The Dispatch Board (Journeyman): Take the dispatch desk's ticket: Undo and Redo buttons, and actions the planning team writes on its own. Change the working dispatch board so every action can be logged, undone and redone, with the tests green throughout.