O'Reilly logo

Design Patterns Java™ Workbook by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required