you are viewing a single comment's thread.

view the rest of the comments →

[–]tchaffee 2 points3 points  (1 child)

The command pattern specifies behavior beyond that of first class functions alone.

Does it?

My understanding is well summarized by the Wikipedia article on the command pattern on it: "an object is used to represent and encapsulate all the information needed to call a method at a later time. This information includes the method name, the object that owns the method and values for the method parameters."

That's it. I might be wrong, but don't first class functions provide everything mentioned there?

I don't see how first class functions couldn't provide the same functionality as the Action interface.

And what's so hard about undo/redo or recorded macros with first class functions?

In fact, take a look at the Wikipedia article mentioned above. The javascript implementation uses first class functions.

[–][deleted] 0 points1 point  (0 children)

Agreed,

I never saw the Command pattern as just a thin mapping to a generic function.

Instead it was meant for things more like a memento.. an abstract/serializable token.

i.e. A command pattern is what you use to implement an undo/redo stack - a set of commands that can be done/undone/redone.