Contents
- 1 What are the responsibilities of originator and caretaker objects in memento design pattern?
- 2 What do we expect from design pattern?
- 3 What is a lazy VAR?
- 4 What is the implementation of the memento pattern?
- 5 How are originator and caretaker used in Memento?
- 6 Where are the contents of a memento stored?
What are the responsibilities of originator and caretaker objects in memento design pattern?
At this point the originator creates a memento object saving its internal state and passes the memento to the caretaker. The caretaker maintains the memento object and performs the operation. The originator would accept the memento, using it to restore its previous state.
What do we expect from design pattern?
Design patterns provide a common vocabulary for designers to use to communicate, document, and explore design alternatives. Design patterns make a system seem less complex by letting you talk about it at a higher level of abstraction than that of a design notation or programming language.
What is Memento pattern in Swift?
Memento is a behavioral design pattern that allows making snapshots of an object’s state and restoring it in future. The Memento doesn’t compromise the internal structure of the object it works with, as well as data kept inside the snapshots.
What is a lazy VAR?
A lazy var is a property whose initial value is not calculated until the first time it’s called. It’s part of a family of properties in which we have constant properties, computed properties, and mutable properties.
What is the implementation of the memento pattern?
Implementation. Memento pattern uses three actor classes. Memento contains state of an object to be restored. Originator creates and stores states in Memento objects and Caretaker object is responsible to restore object state from Memento. We have created classes Memento, Originator and CareTaker.
How are mementos linked to the editor object?
The memento class doesn’t declare any public fields, getters or setters. Therefore no object can alter its contents. Mementos are linked to the editor object that created them. This lets a memento restore the linked editor’s state by passing the data via setters on the editor object.
How are originator and caretaker used in Memento?
Originator creates and stores states in Memento objects and Caretaker object is responsible to restore object state from Memento. We have created classes Memento, Originator and CareTaker. MementoPatternDemo, our demo class, will use CareTaker and Originator objects to show restoration of object states.
Where are the contents of a memento stored?
The pattern suggests storing the copy of the object’s state in a special object called memento. The contents of the memento aren’t accessible to any other object except the one that produced it.