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 - C++ Tutorial
From the course: C++ Design Patterns: Behavioral
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
The Iterator pattern3m 22s
-
(Locked)
Implementing the Iterator pattern4m 37s
-
(Locked)
Using iterators3m 58s
-
(Locked)
The Memento pattern2m 49s
-
(Locked)
Creating a Memento class2m 7s
-
(Locked)
Using Memento classes3m 29s
-
(Locked)
The Null Object pattern2m 40s
-
(Locked)
Creating Null Object classes1m 55s
-
(Locked)
Setting null objects as the default3m
-
(Locked)
Project: Create an instant replay program12m 36s
-
(Locked)
Challenge: Apply the Null Object pattern1m 12s
-
(Locked)
Solution: Apply the Null Object pattern3m 46s
-
-