Strategy (design pattern)

E679880

Strategy is a behavioral design pattern that defines a family of interchangeable algorithms, encapsulates each one, and lets clients switch between them at runtime without changing their code.

All labels observed (3)

How this entity was disambiguated

Statements (50)

Predicate Object
instanceOf behavioral design pattern ⓘ
software design pattern ⓘ
advantage improves code maintainability ⓘ
improves testability of algorithms in isolation ⓘ
promotes composition over inheritance ⓘ
reduces conditional complexity ⓘ
supports adding new algorithms without modifying existing client code ⓘ
alsoKnownAs Policy pattern ⓘ
applicableWhen a class has many conditional statements selecting different behaviors ⓘ
clients should be able to choose algorithms at runtime ⓘ
many related classes differ only in their behavior ⓘ
there are different variants of an algorithm needed ⓘ
belongsToCategory Gang of Four design patterns ⓘ
contrastedWith hard-coded conditional logic for algorithm selection ⓘ
definedIn Design Patterns: Elements of Reusable Object-Oriented Software ⓘ
definesRole ConcreteStrategy implements a specific algorithm ⓘ
Context delegates algorithmic work to the Strategy object ⓘ
Context maintains a reference to a Strategy object ⓘ
Strategy defines a common interface for all supported algorithms ⓘ
describedByAuthor Erich Gamma ⓘ
John Vlissides ⓘ
Ralph Johnson ⓘ
Richard Helm ⓘ
disadvantage increases number of classes ⓘ
may introduce overhead of indirection ⓘ
requires clients to understand different strategies ⓘ
exampleUseCase compression with different compression algorithms ⓘ
payment processing with different payment methods ⓘ
routing with different pathfinding algorithms ⓘ
sorting with different comparison strategies ⓘ
hasParticipant ConcreteStrategy ⓘ
Context ⓘ
Strategy interface ⓘ
linked to: Strategy pattern
primaryIntent define a family of algorithms, encapsulate each one, and make them interchangeable ⓘ
let algorithms vary independently from clients that use them ⓘ
relatedTo Decorator (design pattern) ⓘ
linked to: Decorator

Factory Method (design pattern) ⓘ
linked to: Factory Method

State (design pattern) ⓘ
Template Method (design pattern) ⓘ
linked to: Template Method
supportsFeature algorithm interchangeability ⓘ
elimination of conditional logic based on algorithm choice ⓘ
encapsulation of algorithms ⓘ
open/closed principle ⓘ
runtime selection of algorithms ⓘ
single responsibility principle ⓘ
typicalImplementationLanguage C# ⓘ
C++ ⓘ
Java ⓘ
JavaScript ⓘ
Python ⓘ

How these facts were elicited

Referenced by (3)

Full triples — surface form annotated when it differs from this entity's canonical label.

State (design pattern) → relatedTo → Strategy (design pattern) ⓘ
subject linked to: State
Visitor → relatedTo → Strategy pattern ⓘ
linked to: Strategy (design pattern)
Strategy (design pattern) → definesRole → ConcreteStrategy implements a specific algorithm ⓘ
linked to: Strategy (design pattern)