Recall & Review
beginner
What is the main purpose of the Memento pattern?
The Memento pattern helps save and restore an object's state without exposing its internal details. It allows undo or rollback operations safely.
Click to reveal answer
beginner
Which three roles are involved in the Memento pattern?
1. Originator: The object whose state is saved.<br>2. Memento: Stores the saved state.<br>3. Caretaker: Manages mementos but does not modify them.
Click to reveal answer
intermediate
Why should the Memento hide its state from other objects except the Originator?
To protect encapsulation and prevent other objects from changing the saved state directly, ensuring data integrity.
Click to reveal answer
intermediate
How does the Caretaker interact with the Memento in the pattern?
The Caretaker requests a Memento from the Originator to save state and later gives the Memento back to restore state, but it never changes the Memento's content.
Click to reveal answer
beginner
Give a real-life example that illustrates the Memento pattern.
Think of a text editor with an undo feature. The editor saves snapshots of the document (Mementos). When you undo, it restores the document to a previous snapshot without exposing how the document stores data internally.
Click to reveal answer
Which component in the Memento pattern is responsible for creating a snapshot of the object's state?
✗ Incorrect
The Originator creates a Memento that stores its current state.
What is the role of the Caretaker in the Memento pattern?
✗ Incorrect
The Caretaker keeps Mementos safe but does not modify their content.
Why is it important that the Memento pattern preserves encapsulation?
✗ Incorrect
Encapsulation ensures only the Originator can access and restore its state.
Which scenario best fits the use of the Memento pattern?
✗ Incorrect
Undo requires saving and restoring previous states, which Memento supports.
In the Memento pattern, who is responsible for restoring the saved state?
✗ Incorrect
The Originator uses the Memento to restore its own state.
Explain the roles and responsibilities of the Originator, Memento, and Caretaker in the Memento pattern.
Think about who saves, who holds, and who restores the state.
You got /3 concepts.
Describe a real-world example where the Memento pattern can be applied and explain why it fits.
Consider common software features that let you go back to a previous state.
You got /3 concepts.
