Undo/Redo Pattern

C

Christian H

Hello,

I've tried to find information about how to implement an Undo/Redo pattern.
This article describes such a pattern:
http://www.codeproject.com/csharp/PcObjectUndo.asp , but is a little bit to
narrow, since it only can handle 1 object, and since it only works on
properties.

What if you , in an application, have more than 1 object , and you want to
use undo/redo on them?
What if you'd like it to work on methods as well as properties?

If there is a better pattern than the one in the link, that will let me do
this, please let me know.


Christian H.
 
J

Jussi Jumppanen

Christian said:
I've tried to find information about how to implement an
Undo/Redo pattern.

I implement undo/redo using two stacks. I used a "do" and an
"undo" stack.

When a change is made it goes onto the "do" stack. To undo the
change it is just poped of the "do" stack and pushed onto the
"undo" stack.

What gets pushed and poped are primitive operations encapsulated
in an object. These objects hold all the information required to
do or undo themselves.

I would assume this is quite a common apprach.
What if you , in an application, have more than 1 object,
and you want to use undo/redo on them?

I have about 15 types of objects to handle all the different
situations but they all share a common base class so they
can share a common stack.
If there is a better pattern than the one in the link,
that will let me do this, please let me know.

When I first developed my undo/redo method it took quite
some time to get it working correctly. I started by just
trying to implement a few simple case and then slowly
adding new cases. After a few false starts it all fell
into place quite nicely :)

Jussi Jumppanen
Author of: Zeus for Windows (New version 3.93 out now)
"The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top