Exforsys
+ Reply to Thread
Results 1 to 2 of 2

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's ...

  1. #1
    Shane Mingins Guest

    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.






  2. #2
    Simon Strandgaard Guest

    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





Latest Article

Network Security Risk Assessment and Measurement

Read More...