The strategy template decides " how " to perform certain actions, and the state template decides " when " to perform them.
Using the state template, the state (context) class is freed from knowing what state or type it is and what states or types that are available. This means that the class adheres to the principle of open closure (OCP): the class is closed to changes in which states / types exist, but states / types are open for extensions.
Using the strategy template, the algorithm-used (contextual) class is freed from knowledge of how to perform a specific task (- the "algorithm"). This case also creates an OCP commitment; the class is closed for changes regarding how to accomplish this task, but the design is very open for adding other algorithms to solve this problem.
source share