O'Reilly logo

Scala Design Patterns by Ivan Nikolov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The memento design pattern

Depending on the software we are writing, we might have a requirement to be able to restore the state of an object back to its previous state. The purpose of the memento design pattern is to:

Note

Provide the ability to execute an undo action in order to restore an object to a previous state.

The original memento design pattern is implemented with the help of three main objects:

  • Originator: The object whose state we want to be able to restore
  • Caretaker: The object that triggers the changes to the originator object and uses the memento objects for rollback, if needed
  • Memento: The object that carries the actual state of the originator and can be used to restore to one of the previous states

It is important to know that the memento ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required