flâneur — a map of the web's best reading

Memento

refactoring.guru · 2,426 words · saved by 1 readers

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

Explore this link on the map →

related reading