vendredi 21 décembre 2018

How to use Memento design pattern to restore multiple states of object

As we know, using memento design pattern, we can restore an object to its previous state. I want to modify this to "restore the object to any of its previous states" depending on the requirement. So, let say there are 5 states of object like this -
S1 -> S2 -> S3 -> S4 -> S5
The current state of object is S5. Now, based on some dynamic requirement, I may need to restore its state back to S2. Can it be done with Memento or there is a different design pattern for this altogether. I am trying to do this in Javascript.

Aucun commentaire:

Enregistrer un commentaire