The Memento pattern contains a snapshot of the state of an object, so that the object can return to its original state without having to reveal its content to the rest of the world.
The figure below illustrates the Memento pattern.
The following lists the benefits of using the Memento pattern:
Preserves encapsulation boundaries
Simplifies the originator
When to Use:
You should use the Memento pattern when:
A snapshot of an object's state must be saved so that it can be restored to that state later.
Using a direct interface to obtain the state would expose implementation details and break the object's encapsulation.
memento: an object kept as a reminder or souvenir of a person or event.