mirror of
https://github.com/tmrts/go-patterns.git
synced 2025-04-12 13:30:58 +00:00
789 B
789 B
The Memento pattern allows the state of an object to be saved and restored. It helps us write undo-redo operations through the use of the three componants:
- Originator: It is the actual object whose state is saved as a memento.
- Memento: This is the object which saves the state of the originator
- Caretaker: This is the object that saves multiple mementos. Given an index, it returns the corresponding memento.
The originator defines two methods. savememento() and restorememento()
- savememento()- in this method the originator saves its internal state into a memento object.
- restorememento()- this method takes input as a memento object. The originator restores itself to the pass memento. Hence a previous state is restored.