Exforsys

Online Training

Command->undo()

This is a discussion on Command->undo() within the Software Patterns forums, part of the Testing category; When using the Command pattern to perform actions on a model, if I implement undo, is it the Command object'...


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-03-2003, 09:25 PM
Shane Mingins
Guest
 
Posts: n/a
Command->undo()

When using the Command pattern to perform actions on a model, if I implement
undo, is it the Command object's reponsibilty to undo the action or will it
delegate to the model similar to the action?

E.g the GOF example PasteCommand calls Document.paste() .... would you
implement a method in Document called undoPaste() passing any necessary
parameters need to undo the past command and return the Document to it's
previous state? Or would it depend on whether you already had public
methods on Document that allowed you to reverse the paste command from with
the PasteCommand.undo() method?

--
shanemingins@yahoo.com.clothes

remove clothes before replying

"What are you famous for?" she asked.
"I am simply famous," he replied.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-04-2003, 07:13 PM
Simon Strandgaard
Guest
 
Posts: n/a
Re: Command->undo()

On Thu, 04 Sep 2003 13:25:32 +1200, Shane Mingins wrote:

> When using the Command pattern to perform actions on a model, if I implement
> undo, is it the Command object's reponsibilty to undo the action or will it
> delegate to the model similar to the action?
>
> E.g the GOF example PasteCommand calls Document.paste() .... would you
> implement a method in Document called undoPaste() passing any necessary
> parameters need to undo the past command and return the Document to it's
> previous state? Or would it depend on whether you already had public
> methods on Document that allowed you to reverse the paste command from with
> the PasteCommand.undo() method?


The Memento pattern discuss how to do undo/redo in a nice way.

Before I knew of design patterns I implemented a undo/redo system for my
editor, where every operation had a reverse operation. This lead to
a huge code-bloat. Some years later I discovered the Memento pattern.
It simply takes a full snapshot of the model. Thus only *one* method
for restoring the earlier state is necessary.

More advanced you can take incremental snapshots in order to reduce
the memory consumption.

enough rambling :-)


You can see my current implementation (119 lines of code) of a
undo/redo/macro system for AEditor, here:
http://rubyforge.org/cgi-bin/cvsweb....vsroot=aeditor

--
Simon Strandgaard


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:39 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.