Intent

To record an object internal state without violating encapsulation and reclaim it later without knowledge of the original object.

Where to use & benefits

Structure


Participants

Memento  (Memento)
stores internal state of the Originator object. The memento may store as much or as little of the originator's internal state as necessary at its originator's discretion.

Originator  (Not used)
creates a memento containing a snapshot of its current internal state and uses the memento to restore its internal state

Caretaker  (MainApplet)
is responsible for the memento's safekeeping and never operates on or examines the contents of a memento.

Example

In the demonstration application, the Memento class is used by the MainApplet for the undo operation (specifically for shape creation).

Class Diagram


Source Code Links