oopdesign-patternsstate-patternmemento

Memento design pattern and State design pattern


Memento design pattern is used for restoring objects to previous state, like undo. But we can do undo and redo multiple times. I have read articles multiple times but still unclear to me as to are they similar or complement each other and can be used together.

Can State pattern be related to Memento Design pattern or be used together?


Solution

  • The "state" in the "state pattern" is not the same kind of state that a memento pattern enables. A better name for the state pattern would be the "mode pattern". See this description of it for more details.

    Now, one might use a memento to describe the state of an object that has a mode pattern involved, but that is the only particular relationship they have.