Strategy Pattern
Updated 2026-07-28
Summary
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, the code receives runtime instructions on which of a family of algorithms to use.
Definition
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, the code receives runtime instructions on which of a family of algorithms to use.
Introduction
How to use
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, the code receives runtime instructions on which of a family of algorithms to use.
Mechanism
Refers to a type of behavioral pattern in Design Patterns that encapsulates interchangeable algorithms/strategies, allowing the caller to select different behaviors at runtime.
Practice
In progress 0/4Practice this model in one real situation:
Cases
- Sorting strategies can be switched; payment method strategies can be selected; compression algorithm strategies can be chosen.
Common pitfalls
- Too many strategies can lead to class explosion; or forcing logic that should be combined into strategies.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8Fverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS