Behavioral patterns
Memento
Captures and restores an object's state without breaking its encapsulation.
Article
Memento: a state snapshot without breaking encapsulation
The Memento pattern through a menu editor: Halina saves versions of the menu and returns to them with one click, while the history keeps snapshots without seeing what is inside. Copies instead of references, memory costs and code in five languages.
Related articles
- Prototype – a new object as a copy of a ready-made template
Prototype creates objects by cloning a configured instance instead of building them from scratch. We explain the difference between shallow and deep copies using exam templates as an example.
Challenges
- Game checkpoints easy
- Serialize a binary tree hard
Around the topic
- The Memento Pattern: Saving State Without Breaking Encapsulation video · youtube · ArjanCodes
- Pamiątka / Memento article · web · Refactoring.Guru
- Design Patterns Part 4 – Adapter, Facade, and Memento podcast · apple-podcasts · Coding Blocks
- Design Patterns: Elements of Reusable Object-Oriented Software book · openlibrary · Erich Gamma, John Vlissides, Richard Helm, Ralph Johnson
- Memento article · web · Refactoring.Guru