The memento pattern
The memento pattern will be the last pattern that we will discover together. You will see that this pattern is really interesting to work with and has many uses.
Roles
The role of the memento pattern is to capture an object's internal state and save it externally so that it can be restored later without breaking the encapsulation of this object.
Design
The generic UML class diagram is defined as the following:
Participants
The following are the participants of the memento pattern:
Memento
: This is the class for the objects that saved the internal states of origin objects (or part of this state), such as the introduction of the fact that the saving of a state can be made independent of the object itself. The memento has two interfaces:A complete interface for
Originator
objects that permit access to everything that needs to be saved or restoredA narrow interface to the caretaker that can keep and pass on the memento references, but no more
Originator
: This is the object class...