Without violating encapsulation, captures and externalizes an object‘s
internal state so that the object can be restored to this state later.
Category:
Behavioral
UML Diagram:
Description of the Demonstration:
As this "game" progresses, the current state of all objects in the game are
updated in an instance of GameMemento. Once each second a "backup" file is
written to disk. If for some reason the game crashes or the player want to
"undo" the last action they can terminate the program and restart. Upon
startup the Game checks to see if there is a backup file present and asks
the user if they want to use it. If so the file is opened, read, and the game
reset to the state it was in just before being terminated.
Code:
Click here to download a
zip file containing all the source files and an executable of the
Demonstration. See the _ReadMe.txt file in the zip.