Importance of Memento Design Pattern

Issath Sesni
2 min readJun 5, 2021
Image by Refactoring.guru

What is Memento design pattern and why?

It is a behavioral design pattern used to undo/rollback/revert the state of an object to its previous state. It has three pillers,

  1. Originator :- It will maintain the state.
  2. Care taker :- Keep the track of originator.
  3. Memento :- It is just a POJO(Plain Old Java Object) means it is an ordinary java object.

Originator always couples with memento and pass the state to the care taker. It should hold sufficient information to restore the previous object. So, if we want to get the previous states of an object, we should communicate with the care taker, then it will return the state.

Note : We cant undoable in some situation. In that case, we have to use this pattern.

UML diagram of Memento Design Pattern

Advantage

We can use serialization to achieve this pattern implementation.

Drawback

If the originator has a huge size, then memento object also has a huge size and it uses lot of memory.

Happy Learning.

--

--