jargon

Comparison

Command patternvsStrategy pattern

Command pattern

the request became an object with an execute method, so you could put it in a queue, log it and undo it.

Turning an invocation into a first-class object carrying its receiver and arguments, so it can be stored, passed, queued, retried, logged or reversed. That reification is the point — a strategy and a command can be identical in shape, and the difference is that a strategy is how to do something and a command is a particular thing to do. It is the object-level relative of every persisted-request idea, from job queues to event sourcing.

Full entry →

Strategy pattern

the class takes the algorithm as a constructor argument, and choosing a different one is a different argument.

Putting an interchangeable algorithm behind an interface so the object using it does not know which one it has. It is the pattern the caller chooses — a pricing rule, a sort comparator, a retry policy passed in from outside. In a language with first-class functions a strategy is usually just a function parameter, and saying so is a better answer than drawing the class diagram.

Full entry →

Related comparisons