Command pattern and undo

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Command pattern and undo

Schwab,Wilhelm K
Hello all,

This is perhaps not what you might think :)  I am considering rewriting
something written using the command pattern, possibly with a more direct
approach.

I recognize the power of representing actions with objects that carry
data, and acknowledge that it might be inappropriate to seek another
approach (it's a long story) in this case.  However, the command-based
code has gratuitous indirection (or is it appropriate use of double
dispatch<g>) that drives me nuts every time I look at it.

Any experience or advice either way?

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Command pattern and undo

Chris Uppal-3
Bill,

> I recognize the power of representing actions with objects that carry
> data, and acknowledge that it might be inappropriate to seek another
> approach (it's a long story) in this case.  However, the command-based
> code has gratuitous indirection (or is it appropriate use of double
> dispatch<g>) that drives me nuts every time I look at it.

Not at all sure what you mean here, but if the code is confusing then that
seems like a suficient justification for changing it (assuming you can).

But take a backup first ;-)  One of the things that I find myself doing quite
often is spotting a neat simplification I can make to some code, and starting
in to apply it, only to discover about 3/4 of the way through that it won't
work in some odd case.  "Ah, /that's/ why I did it like that...".  :-(

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Command pattern and undo

Sebastián Sastre
In reply to this post by Schwab,Wilhelm K
I don't understand why you have to use a pattern when you can avoid it at
all. I mean, you can make better thigns than patterns: you can make exactly
what you need.

My advice is, don't try to force yourself to apply a pattern when it don't
fit, specially if it will make things more complex than you need.

I use patterns more as a source of inspiration so I can be not too much
creative in the design, but accurate and never limitated by it.

regards,

Seb

"Bill Schwab" <[hidden email]> escribió en el mensaje
news:ck1rcu$19sq$[hidden email]...

> Hello all,
>
> This is perhaps not what you might think :)  I am considering rewriting
> something written using the command pattern, possibly with a more direct
> approach.
>
> I recognize the power of representing actions with objects that carry
> data, and acknowledge that it might be inappropriate to seek another
> approach (it's a long story) in this case.  However, the command-based
> code has gratuitous indirection (or is it appropriate use of double
> dispatch<g>) that drives me nuts every time I look at it.
>
> Any experience or advice either way?
>
> Have a good one,
>
> Bill
>
> --
> Wilhelm K. Schwab, Ph.D.
> [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Command pattern and undo

Schwab,Wilhelm K
Seb,

> I don't understand why you have to use a pattern when you can avoid it at
> all. I mean, you can make better thigns than patterns: you can make exactly
> what you need.

It's not that I feel bound to the details of the pattern; it's that the
general concept of the pattern makes a lot of sense for the system in
question.  I sometimes find my self wishing that it didn't.

Fair or not, my sense is that the command pattern makes things more
complicated, with the advantage of making undo/redo/etc. simpler.  In my
case, it helps make sequential sense out of a chaos of inputs.  If I
dump it, I will have to make up for the extra degrees of freedom
available to the "commands".  I have a few ideas on the latter.

Chris might have nailed it with his "backup and try it" recommendation.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]