Contents
Which of the following is consequence of Memento design pattern?
Consequences. The Memento pattern has several consequences: Preserving encapsulation boundaries. Memento avoids exposing information that only an originator should manage but that must be stored nevertheless outside the originator.
When to use Memento pattern?
Use the Memento pattern when you want to produce snapshots of the object’s state to be able to restore a previous state of the object. The Memento pattern lets you make full copies of an object’s state, including private fields, and store them separately from the object.
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.
Who is responsible for storing mementos in the Memento design pattern?
Caretaker is the helper class that is responsible for storing and restoring the Originator’s state through Memento object. A Caretaker object keeps and holds the Mementos, but never modify the Mementos.
What is KVO Swift?
KVO, which stands for Key-Value Observing, is one of the techniques for observing the program state changes available in Objective-C and Swift. The concept is simple: when we have an object with some instance variables, KVO allows other objects to establish surveillance on changes for any of those instance variables.
Can a caretaker change an opaque memento object?
The memento object itself is an opaque object (one which the caretaker cannot, or should not, change). When using this pattern, care should be taken if the originator may change other objects or resources – the memento pattern operates on a single object.
What do you need to know about the memento pattern?
Memento pattern. Jump to navigation Jump to search. The memento pattern is a software design pattern that provides the ability to restore an object to its previous state (undo via rollback). The memento pattern is implemented with three objects: the originator, a caretaker and a memento. The originator is some object that has an internal state.
Can a client request a memento from the originator?
Only the originator that created a memento is allowed to access it. A client (caretaker) can request a memento from the originator (to save the internal state of the originator) and pass a memento back to the originator (to restore to a previous state).
What does the caretaker class do in UML?
In the above UML class diagram, the Caretaker class refers to the Originator class for saving ( createMemento ()) and restoring ( restore (memento)) originator’s internal state. (2) restore (memento) by restoring state from the passed in Memento object.