Importance of Memento Design Pattern

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.

--

--

--

Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to inspect dynamic dropdown WebElements?

Autoptimize Plugin Setting WordPress Optimization 100/100 Gtmetrix

Multiple Pointers Pattern: 2 pointers technique

Understanding the JavaScript Spread Operator — From beginner to expert

Angular: Architecture Considerations

How to install Ionic on your machine?

10 JavaScript Productivity Booster That Your Teammates Are Not Allowed to Know

Facebook’s Prepack — The Next Killer In The JavaScript Zone

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Issath Sesni

Issath Sesni

Software Engineer

More from Medium

CS373 Spring 2022: Isaac Adams

What are the biggest myths when choosing an external software development partner?

Why I’m deleting Microsoft OneDrive (Mac Edition)

How to approach VR Software Development