The Strategy design pattern provides a solution:
Encapsulate an algorithm
in a separate Strategy object.
A class
delegates an algorithm
to a
Strategy object
instead of implementing an algorithm directly.
Describing the Strategy design in more detail is the
theme of the following sections.
See Applicability section for all problems Strategy can solve.
Strategy objects:
Strategy | algorithm(…)).
Strategy1,Strategy2,…)
that implement the Strategy interface
(encapsulate an algorithm
[BGI]).
Context)
delegates the responsibility for performing an algorithm
to a Strategy
object
(strategy.algorithm(…)).
Strategy object,
which it uses to perform an algorithm, and
even more, the Strategy object
can be exchanged dynamically.
Background Information