Things To Consider When Creating An Undo Mechanism

Brainstorming an undo-redo mechanism at work today and here are a couple of thoughts:

  1. There are so many mechanisms that already exist. A quick google on CodeProject gives five right away (without extra digging). NIH is foolish. :)
  2. Undo actions are transactions. However, they might not be just for your business objects, but also for your UI. An undo transaction might be only for the UI (but not likely).
  3. We've considered using Action/Reverse-Action, but this is double the code and development time. Reverse actions might also not be possible at times, since multithreading and events might cause non-deterministic action order.
  4. System.Transactions is nice, but it only works in one way – Undo. Creating a Redo with dual transaction directions might work, but it seems like a kludge.
  5. This article offers the closest solution to what we need, but it causes debugging pains and supports neither transactions nor UI element changes.

Anyone know of any good solutions?


2 thoughts on “Things To Consider When Creating An Undo Mechanism

  1. On one project, instead of implementing “undo” for all of our commands, we just reloaded all data from the database into our objects and re-run all commands apart from the command that the user wished to undo.It could be a bit slow if the user had done a lot before a save, as we wrote the users changes to the database on the save and cleared the command stack at that point.Undo is VERY hard if you have other users changes the data in a way that can make the undo not valid….

  2. Another way is the immutable (internal) state, in which a change to a property pops that value into a history stack.
    Depending on your choosen foundation, it does require coding certain patterns per property, class and containers. Using codegen or a custom compiler you can overcome this repeatitive strain.
    For various elaborate reasons I’ve chosen to build a custom compiler.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s