Hey guys,
Does anyone have experience using the command
pattern<http://en.wikipedia.org/wiki/Command_pattern>?
I’m looking for a few things that this pattern seems to help with.
-
Undo/redo (preferable multi-level and persistent)
-
Action logging (what the user has done, in which order, and where things
went wrong using which arguments)
- Distribution of commands via a network (serialisation, asynchronous
execution)
I took a whack at it and found it rather straightforward to make a
scripting-language out of it.
The Command Pattern <https://gist.github.com/mottosso/f5722c4afd1b0791c4d3>
There’s an example run at the bottom, but the ‘gist’ of it is this:
______________________________________________________
| |
| Command Pattern - Demonstration |
| Author: Marcus Ottosson <[email protected]> |
|______________________________________________________|
* Available commands
cls
create
data
delete
exit
help
history
redo
undo
update
verbosity
command> create key value
command> create age 5
command> create length 1.57
command> data
age=5
length=1.57
key=value
command> undo
command> redo
command> help update
Update existing value in DATASTORE
Args:
key: Identifier for value
value: Value for identifier
Precondition:
`key` must already exist
Example:
command> update age 5
The main questions are about two aspects of it’s design:
*History is stored as class attributes*
Which means that commands add themselves to history, which wouldn’t work
too great if they are accessed from separate threads.
*History is stored as Python objects, as opposed to simple strings*
Which means that history would be tricky to serialise and persist on disk
or across a network.
Thoughts?
Best,
Marcus
--
*Marcus Ottosson*
[email protected]
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAc6RTpxT%3Dtppa4GLrvWKZvN_A9qsC0riZQN27NJPcAhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.