In this article you will learn about the Memento Design Pattern.
The Memento Design Pattern is about recording state. In a racing game there are sometimes the “ghosts” that is a shadow of your best run. These ghosts could have all their movements recorded by a memento and replayed during the game.A memento has a simple implementation, it has a class to store the properties that will be recorded and a recorder that will store the values.
And we need a recorder to store a list of mementos.
Using it:
At this point we have 3 states saved on the recorder. We can iterate using the states by calling Forward and Rewind. Currently our car is at the following position:
But if we call the recorder method Rewind:
Our car instance will now have X and Y set to 20.
Exploring Design Pattern for Dummies