Applying Memento
In the preceding chapter, you used the PROTOTYPE pattern to design a simulation that let users speculatively create new machine simulators from existing ones. Your users like the simulation, but they sometimes make changes that they wish they could undo.
You might consider using the javax.swing.undo package to support an undo operation. However, the undo package focuses its support on operations for textual Swing components. In this application, it is simpler to apply the MEMENTO pattern to save and to restore the state of the simulation at key points.
Each time the user adds or moves a machine in the visualization, your code will create a memento of the simulated factory and add it to a stack.
Each time the user clicks the Undo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access