Example class diagram

A classic example of the memento design pattern that comes to mind is text editors. We can always undo whatever we have changed. We will present something similar in our class diagram and example.

The following is the class diagram:

As you can see in the preceding diagram, our caretaker is the TextEditorManipulator. It automatically saves the state in the states stack on every manipulation. The TextEditor implements the Originator and creates a memento object and restores from one. Finally, the TextEditorMemento is the concrete memento object that our text editor will be using to save the state. Our state is just the ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.