Memento
Usage
- Also known as: Snapshot; Token
- Capture and restore an object's internal state
- Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later
Diagram
Participants
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.
- Protect against access by objects of other than the originator.
- Mementos have effectively two interfaces:
- Caretaker sees a narrow interface to the Memento -- it can only pass the memento to the other objects.
- Originator, in contrast, sees a wide interface, one that lets it access all the data necessary to restore itself to its previous state.
Originator
- Ideally, only the originator that Produces the memento would be permitted to access the memento's internal state.
Caretaker
- Creates a memento containing a snapshot of its current internal state.
- Uses the memento to restore its internal state
- Is responsible for the memento's safekeeping
- Never operates on or examines the contents of a memento.
Resources URL:
notes/design_patterns/resources
Sources URL:
notes/design_patterns/sources
