23

Possible Duplicate:
Design Pattern for Undo Engine

In general, how do you deal with supporting an "undo" feature in your application? I have worked on web apps and desktop apps alike, and I have never really felt comfortable with any "undo" system I've made.

Community
  • 1
  • 1
tenfour
  • 36,141
  • 15
  • 83
  • 142

3 Answers3

35

I believe it should be Command design pattern.

Here is article about multilevel Undo/Redo with Command pattern.

EDIT: Here is second about multilevel Undo/Redo with Memento pattern.

So probably it can be done with both.

jethro
  • 18,177
  • 7
  • 46
  • 42
9

Check out the Memento Pattern

Dave McClelland
  • 3,385
  • 1
  • 29
  • 44
8

I'd vote in favor of Command pattern over Memento. Memento pattern would be much costlier then Command patterns for Undo/Redo functionality.

Capturing and Restoring object state will be quite an expensive affair compared to just doing or undoing an action on any compatible object.

this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137