Memento
Memento is a behavioral design pattern that lets you save and restore the previous state of an object without revealing the details of its implementation. Imagine that you’re creating a text editor app. In addition to simple text editing, your editor can format text, insert inline images, etc. At some point, you decided to let users undo any operations carried out on the text. This feature has become so common over the years that nowadays people expect every app to have it. For the implementation, you chose to take the direct approach. Before performing any operation, the app records the state of all objects and saves it in some storage. Later, when a user decides to revert an action, the app fetches the latest snapshot from the history and uses it to restore the state of all objects. Before executing an operation, the app saves a snapshot of the objects’ state, which can later be used to restore objects to their previous state. Let’s think about those state snapshots. How exactly woul
/ Design Patterns / Behavioral Patterns Memento Also known as: Snapshot Intent Memento is a behavioral design pattern that lets you save and restore the previous state of an object without revealing the details of its implementation. Problem Imagine that you’re creating a text editor app. In addition to simple text editing, your editor can format text, insert inline images, etc. At some point, you decided to let users undo any operations carried out on the text. This feature has become so common over the years that nowadays people expect every app to have it. For the implementation, you chose
related reading
- mymind is the extension for your mind.mymind.com
- Staterefactoring.guru
- Malleable software: Restoring user agency in a world of locked-down appsinkandswitch.com
- Design with materials, not features | thesephist.comthesephist.com
- Design Patternsgrantslatton.com
- Design Patternsrefactoring.guru
- artima - Josh Bloch on Designartima.com
- Information hidingen.wikipedia.org
- Understanding useMemo and useCallback • Josh W. Comeaujoshwcomeau.com
- Memoization - Wikipediaen.wikipedia.org
- Immutable object - Wikipediaen.wikipedia.org
- Classification of patternsrefactoring.guru