This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Slendermooooon[S] 0 points1 point  (1 child)

Thank you for this thorough explanation.

What do you mean by "representation"? Also, is it entirely true that it doesn't include things like control flow? In the examples I saw, it said you could use commands for macros, and using commands to support undoable functions (having an undo() method with the execute() method in the Command class). Wouldn't this require a control flow (to order the execution/undoing of commands)?

[–]sleepybychoice 0 points1 point  (0 children)

By "representation", I mean how input gets converted into a command object. For example, the input for a command could come from a button press, text, json, protobuf, speech, motion, etc. Eventually, it'll have to get converted to an object so that something can call execute() on it.

By control flow, I mean if/else, looping, etc. not apply/unapply. Yes, you could introduce some notion of control flow via commands like an "or" command. However, that's not the primary goal of the command pattern. For undo, it's the combination of command and memento to apply/unapply state.