From the course: C++ Design Patterns: Behavioral

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

The Memento pattern

The Memento pattern

- [Instructor] Okay. It's time to take a look at our next pattern which is called the memento pattern. The memento pattern is used when we need a way to prevent most parts of our program from modifying some saved object until we say so. As an example of this, earlier in the course when we looked at the command pattern, we used the example of a hypothetical drawing program. Now, if we wanted to give users the ability to undo their actions in a program like this, what we'd need is some way of freeze-drying the different states that the canvas had been in, in order to allow us to restore those states. And we'd want to prevent other objects in the program from tampering with these saved states, right? Think about how frustrating it would be if you clicked Undo and the state that it went back to was a little different from the one you actually had before. So the memento pattern is used as a way to temporarily freeze data in our…

Contents