Origin: |
Grand 98 (see also Memento, GoF 95) |
Reason: |
To capture and later restore the state of an object. |
Synopsis: |
Define an object responsible for capturing and restoring
the state of objects. These objects should implement a
common interface.
|
Example: |
A player would like to play a long game in short
temporally-separated intervals.
|
Solution: |
Originator |
An object of this class can have its state saved and restored.
|
MementoIF |
Interface to access Memento objects.
Must protect the encapsulation of the Originator's state.
|
Memento |
Private static class of Originator which
implements the MementoIF interface.
|
Caretaker |
Maintains one or more Memento objects.
May hold them in memory or store them on disk.
|
|
See also: |
Command
(similarly, it allows state changes to be undone)
|