2005-04-13

General Undo Redo Framework works now

Undo and Redo some times needed in some projects. The undo/redo I meant is not talking about in GUI perspective but from object state view. This framework is a part of my master thesis. It is called "General" 'cause client programmer doesn't has to make big changes on existing codes. Just declare a "command block" is ok. A command block is a undo/redo unit, it can contain a number of methods or operations. In another word, it identicates a undo/redo step. With this framework, client developer just "plugs" it into existing project, and the project has the unlimited times (only in possible case) undo/redo feature. I think it's nice.

This program is implemented by Java reflection and AspectJ. To get better performance, I didn't store whole object trees snap shot in memory or disk. It definitely will construct a heavy overhead. And it is more obvious if unlimited times undo/redo is needed. So Memento pattern is not used either.

Shortly, the strategy to achieve the requirement are:
-AOP aspect acts as undo/redo observer, it capture any attempt of changing an object(mainly fields changing)
-Save the changing field old value into some structrue, e.g. hashtable , reflection used here.Save the method objects, owner object and arguments, which lead to an object change within a single command in certain order, reflection used as well.
-Undo - get the right command from command manager, restore the old values of changed fields.
-Redo - get the right command and execute all methods stored in command.methodlist again.

Object references, Collections and navigation between associated classes like composition, aggregation are some points I paied attention. Especially the last one, I found a bug about it during redo, and fixing it cost me one day! (Not all the time :) )
More testing is needed on this framework.

No comments:

Post a Comment