We may earn an affiliate commission when you visit our partners.

Memento Pattern

Save
May 11, 2024 3 minute read

The Memento Pattern is a software design pattern that allows an object to restore itself to a previous state. This pattern is useful when you need to undo or redo an action, or when you need to keep track of the history of an object.

How the Memento Pattern Works

The Memento Pattern uses three classes: the Originator, the Memento, and the Caretaker. The Originator is the object that wants to be able to restore itself to a previous state. The Memento is the object that stores the state of the Originator. The Caretaker is the object that manages the Mementos.

When the Originator wants to save its state, it creates a Memento. The Memento stores the state of the Originator in a way that can be restored later. The Originator then passes the Memento to the Caretaker.

When the Originator wants to restore itself to a previous state, it asks the Caretaker for the Memento. The Caretaker then gives the Memento to the Originator, which restores itself to the state stored in the Memento.

Benefits of Using the Memento Pattern

The Memento Pattern has several benefits. First, it allows objects to be restored to a previous state without having to recreate the state from scratch. This can save time and resources.

Second, the Memento Pattern allows multiple Mementos to be stored, which allows objects to be restored to multiple previous states. This can be useful for debugging or for implementing undo/redo functionality.

Third, the Memento Pattern is relatively easy to implement. This makes it a good choice for projects that require the ability to restore objects to previous states.

Examples of the Memento Pattern

Path to Memento Pattern

Take the first step.
We've curated two courses to help you on your path to Memento Pattern. Use these to develop your skills, build background knowledge, and put what you learn to practice.
Sorted from most relevant to least relevant:

Share

Help others find this page about Memento Pattern: by sharing it with your friends and followers:

Reading list

We've selected 14 books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Memento Pattern.
Is the definitive work on design patterns and provides a comprehensive overview of the Memento pattern. It explains the purpose, structure, and implementation of the pattern, and provides numerous examples of its use in real-world applications.
Provides a more accessible introduction to design patterns, including the Memento pattern. It uses a conversational style and numerous diagrams to explain the concepts in a clear and concise manner.
Discusses the Memento pattern in the context of enterprise application architecture. It explains how to use the pattern to implement loosely coupled, scalable, and maintainable systems.
Discusses the Memento pattern as a technique for implementing domain-driven design principles. It explains how to use the pattern to create software applications that are closely aligned with the business domain.
Discusses the Memento pattern as a technique for implementing concurrent and networked software systems. It explains how to use the pattern to create software applications that are scalable, reliable, and maintainable.
Discusses the Memento pattern as a technique for implementing test-driven development practices. It explains how to use the pattern to create software applications that are testable, maintainable, and reliable.
Discusses the Memento pattern as a technique for implementing clean architecture principles. It explains how to use the pattern to create software applications that are loosely coupled, scalable, and maintainable.
Discusses the Memento pattern as a technique for implementing dependency injection principles. It explains how to use the pattern to create software applications that are loosely coupled, testable, and maintainable.
Discusses the Memento pattern as a technique for implementing continuous delivery practices. It explains how to use the pattern to create software applications that are releasable, testable, and maintainable.
Discusses the Memento pattern as a technique for implementing software engineering principles. It explains how to use the pattern to create software applications that are reliable, maintainable, and efficient.
Discusses the Memento pattern as a technique for implementing software engineering principles at Google. It explains how to use the pattern to create software applications that are scalable, reliable, and maintainable.
Table of Contents
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser