jargon

Comparison

Higher-order functionvsStrategy pattern

Higher-order function

the function's argument is another function, and what it actually does depends entirely on what you passed.

A function that takes or returns another function. It is the mechanism behind map, filter, sort comparators, decorators, middleware and retry helpers — anywhere the shape of a computation is fixed and one step of it is not. The pattern-catalogue equivalents are strategy and template method, both of which reduce to a higher-order function in a language with closures.

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