Design patterns·Who calls whom, and when
the class takes the algorithm as a constructor argument, and choosing a different one is a different argument.
Strategy pattern
Also calledstrategy, policy pattern, pluggable algorithm
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.