Memento design pattern

Kishara Buddika
1 min readJun 24, 2022

--

Memento pattern is a behavioral design pattern. To return an object’s state to a prior state, the memento pattern is utilized. You might wish to preserve checkpoints as your program develops so that you can subsequently restore to those checkpoints. Memento design pattern has three design components.

  1. Originator — What we need to maintain the state.
  2. Memento — The component that will preserve the originator’s state
  3. Caretaker — Who keep the track of the originator

When we are implementing this, originator coupled with memento and the pass state to the caretaker. Whenever we need to go to previous state we talk to the caretaker and we check what is the previous state and move.

Benefits of using memento design pattern

  • This design pattern offers a recovery mechanism for any failure.
  • It offers a simple method for keeping track of an object’s life cycle history.
  • Without sacrificing encapsulation, it stores the state of the object.
  • Without compromising the object’s encapsulation, it creates snapshots of the object’s state.

Thank you for reading! If you enjoyed please leave a clap and follow my page.

Kishara Buddika

--

--

Kishara Buddika

I'm an Associate Software Engineer and a professional Graphic Designer. A blogger with interests in Technology, Creativity and Business. I write for explorers.