Bird
0
0
LLDsystem_design~5 mins

Memento pattern in LLD - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AOriginator
BCaretaker
CMemento
DClient
What is the role of the Caretaker in the Memento pattern?
AStore and manage Mementos without changing them
BModify the saved state
CCreate Mementos
DRestore the Originator's state directly
Why is it important that the Memento pattern preserves encapsulation?
ATo allow other objects to change the state
BTo avoid saving the state
CTo hide the internal state from all except the Originator
DTo make the state public
Which scenario best fits the use of the Memento pattern?
ALogging user actions
BUndo functionality in an application
CSharing data between objects
DEncrypting data
In the Memento pattern, who is responsible for restoring the saved state?
AMemento
BClient
CCaretaker
DOriginator
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.