Return to site

📐 Design Patterns: Memento

The _____ Pattern is a design pattern that captures and externalizes an object's internal state, allowing it to be saved and restored later.

It's often used for implementing undo and redo features in applications.

* Pipeline

* Chain of Responsibility

* Command

* Memento

#programming #design #pattern #memento

This enables you to save and restore the object's state at a later time, providing a way to undo or revert changes.

Key components of the Memento Pattern:

* Originator:

The Originator is the object whose state needs to be saved.

It creates a Memento object to represent its state and can restore its state from a Memento.

* Memento:

The Memento is an object that stores the state of the Originator.

It has methods to get and set the state but does not reveal the internal details of the Originator.

* Caretaker:

The Caretaker is responsible for keeping track of and managing Memento objects.

It can save and retrieve the Originator's state using Mementos.

broken image
broken image

The Memento Pattern is particularly useful for implementing features like undo and redo functionality in applications, as well as for managing checkpoints and history in various systems.

It allows you to capture an object's state at specific points in time and restore it as needed, all while keeping the object's internal details hidden.

Details: https://refactoring.guru/design-patterns/memento

Wiki: https://en.wikipedia.org/wiki/Memento_pattern