Strategy Pattern

In computer programming, the strategy pattern is a particular software design pattern, whereby algorithms can be selected on-the-fly at runtime depending on conditions, like strategies in a war situation. The strategy pattern is useful for situations where it is necessary to dynamically swap the algorithms used in an application. The strategy pattern is intended to provide a means to define a family of algorithms, encapsulate each one as an object, and make them interchangeable. The strategy pattern lets the algorithms vary independently from clients that use them. The following class diagram shows the strategy pattern basically consists of a context class and a set of strategy classes. An abstract strategy class is defined that custom strategy classes can implement. Each strategy object implements the algorithm that makes it unique. The client instantiates the strategy class and passes it as an argument when it calls the constructor of the context class. The client is then able to call methods on the context object and any strategy specific methods as necessary. Because the context creates an instance of the abstract strategy, the client is effectively using polymorphism to call strategy-specific methods on the context object.

See also

External links

 

<< PreviousWord BrowserNext >>
gcm
elizabeth stuart
king diamond
karl pearson
marjorie merriweather post
reign of fire
c. w. post
frederick v, elector palatine
les nabis
odilon redon
itzpapalotl
lilo & stitch
tomoanchan
saxtead green post mill
rope dress
builder pattern
factory method pattern
prototype pattern
composite pattern
decorator pattern
proxy pattern
command pattern
interpreter pattern
mediator pattern
observer pattern
state pattern
template method pattern
mrkisch oderland
hierarchical visitor pattern
balking pattern
guarded suspension
scheduler pattern
read write lock pattern
double checked locking
chain of responsibility pattern
disable job requests while running job pattern
alderaan
thomas fuller
swing (genre)
scheduled task pattern
optimus prime (person)
lanarkshire
heavy fighter
ali ahmeti