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.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: