In computer programming, the strategy pattern (also known as the policy pattern) is a behavioral software design pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly, code receives runtime instructions as to which in a family of algorithms to use.[1]
Strategy lets the algorithm vary independently from clients that use it.[2] Strategy is one of the patterns included in the influential book Design Patterns by Gamma et al.[3] that popularized the concept of using design patterns to describe how to design flexible and reusable object-oriented software. Deferring the decision about which algorithm to use until runtime allows the calling code to be more flexible and reusable.
For instance, a class that performs validation on incoming data may use the strategy pattern to select a validation algorithm depending on the type of data, the source of the data, user choice, or other discriminating factors. These factors are not known until runtime and may require radically different validation to be performed. The validation algorithms (strategies), encapsulated separately from the validating object, may be used by other validating objects in different areas of the system (or even different systems) without code duplication.
Typically, the strategy pattern stores a reference to code in a data structure and retrieves it. This can be achieved by mechanisms such as the native function pointer, the first-class function, classes or class instances in object-oriented programming languages, or accessing the language implementation's internal storage of code via reflection.
^Eric Freeman, Elisabeth Freeman, Kathy Sierra and Bert Bates, Head First Design Patterns, First Edition, Chapter 1, Page 24, O'Reilly Media, Inc, 2004. ISBN 978-0-596-00712-6
^Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley. pp. 315ff. ISBN 0-201-63361-2.{{cite book}}: CS1 maint: multiple names: authors list (link)
In computer programming, the strategypattern (also known as the policy pattern) is a behavioral software design pattern that enables selecting an algorithm...
actions. A strategy describes how the ends (goals) will be achieved by the means (resources). Strategy can be intended or can emerge as a pattern of activity...
state pattern can be interpreted as a strategypattern, which is able to switch a strategy through invocations of methods defined in the pattern's interface...
modules, and implement complex, non-deterministic control strategies Chain-of-responsibility pattern Command objects are handled or passed on to other objects...
existing strategypattern, and that this should, therefore, be the preferred terminology for describing the design pattern at hand. Strategypattern "The...
regarded as a special case of the State pattern and the Strategypattern. It is not a pattern from Design Patterns, but is mentioned in Martin Fowler's Refactoring...
description language Factory pattern Inversion of control Plug-in (computing) Strategypattern AngularJS Service locator pattern Parameter (computer programming)...
In software engineering, a design pattern describes a relatively small, well-defined aspect (i.e. functionality) of a computer program in terms of how...
A chart pattern or price pattern is a pattern within a chart when prices are graphed. In stock and commodity markets trading, chart pattern studies play...
as pattern – a consistent pattern of past behavior, with a strategy realized over time rather than planned or intended. Where the realized pattern was...
A strategy game or strategic game is a game (e.g. a board game) in which the players' uncoerced, and often autonomous, decision-making skills have a high...
discoverable by failing unit tests. Remove shortcut code (see the strategypattern): A simplified code path may hide bugs in a more generic code path...
Pattern recognition is the task of assigning a class to an observation based on patterns extracted from data. While similar, pattern recognition (PR) is...
In American politics, the Southern strategy was a Republican Party electoral strategy to increase political support among white voters in the South by...
quite large in some games, and 4X strategy games are known for having the largest. A build order is a linear pattern of production, research, and resource...
The service locator pattern is a design pattern used in software development to encapsulate the processes involved in obtaining a service with a strong...
strategy, and is used in two distinct, though equally important senses. The dynamics of strategy and performance concerns the ‘content’ of strategy –...
software design pattern is an event handling strategy that can respond to many potential service requests concurrently. The pattern's key component is...
Many object-oriented design patterns are expressible in functional programming terms: for example, the strategypattern simply dictates use of a higher-order...