Memento

Capture and restore object state

Overview

Memento lets you save and restore the previous state of an object without revealing the details of its implementation (breaking encapsulation).

Code Example

java
1public class Editor {
2    private String content;
3    public EditorMemento save() { return new EditorMemento(content); }
4    public void restore(EditorMemento m) { content = m.getContent(); }
5}

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Memento - Behavioral Patterns | LLD | Revise Algo