Strategy pattern
The Strategy pattern is a design pattern that encapsulates interchangeable algorithms or behaviors behind a common interface so they can be selected independently of their users.
Software Design for Python Programmers
A strategy is an encapsulated algorithm that provides interchangeable behavior for a client.
- How it is used
- Manages interchangeable algorithm families when runtime decisions and independently changeable behavior are required.
- How deep it goes
- Works from inheritance problems through interfaces, composition, delegation, setters, concrete strategies, and runtime replacement.
- Examples
- Demonstrates sports teams using player-recruitment and venue strategies, including replacing volleyball's open field with a stadium.
- What you can do after
- Build it from scratch by separating algorithm families behind interfaces and selecting or replacing implementations at runtime.
Read how Software Design for Python Programmers explains strategy pattern →
Object-Oriented Software Design in C++
The Strategy Design Pattern is a behavioral design pattern that encapsulates interchangeable algorithms behind a common interface so one can be selected independently of the client that uses it.
- How it is used
- Manages interchangeable algorithm families when an application must choose behavior at run time.
- How deep it goes
- Explains interfaces, composition, delegation, replacement, and trade-offs, but stops short of a library-based implementation.
- Examples
- Uses baseball, football, and volleyball strategies for recruiting players and reserving stadiums or open fields.
- What you can do after
- Build it from scratch by defining strategy interfaces, implementing algorithm variants, aggregating them in a client, and switching them at run time.
Read how Object-Oriented Software Design in C++ explains strategy pattern →
Microservices Patterns, Second Edition
The Strategy pattern is an object-oriented design pattern that encapsulates interchangeable algorithms behind a common interface.
- How it is used
- Uses interchangeable algorithms to support different overdraft policies in a banking application.
- How deep it goes
- Defines the interface, concrete strategy classes, and using class through a banking example.
- Examples
- Uses banking overdraft policies with varying limits and fees as its concrete example.
- What you can do after
- Build a class-based design that separates an algorithm’s interface, concrete policies, and using class.
Read how Microservices Patterns, Second Edition explains strategy pattern →
Data-Oriented Programming in Java
The Strategy pattern encapsulates interchangeable implementations of an operation behind a common interface.
- How it is used
- Organizes manifest-driven ingestion by isolating transformation and persistence choices behind interfaces.
- How deep it goes
- Defines interfaces, implementations, factory selection, and orchestration, while deferring broader abstraction through Template Pattern.
- Examples
- Uses account, invoice, and dispute files, transformers, repositories, a manifest, and a shared UpdatesAndInserts record.
- What you can do after
- Apply it via Java interfaces and a factory to add ingestion behaviors without changing the main processing loop.
Read how Data-Oriented Programming in Java explains strategy pattern →
Also covered in
- AI-Powered Developer: Build software with ChatGPT and Copilot
- Write Powerful Rust Macros
- F# in Action: A Revised Edition of Get Programming with F#
What to know first
- accessor methodAn accessor method or function is a callable that reads, computes, or assigns a value associated with a property, field, or data element.
- design patternA design pattern is a reusable, general solution structure for a recurring software design problem.
- enumAn enum is a type whose values are selected from a finite set of named alternatives.
- inheritanceInheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
Related concepts
- patternkind of · A pattern is a reusable approach to solving a recurring problem within a particular context.
- design patternkind of · A design pattern is a reusable, general solution structure for a recurring software design problem.
- abstract factory design patterncontrasts with · The Abstract Factory is a creational design pattern that provides an interface for creating families of related objects without specifying their concrete classes.
- machine learninguses · Machine learning is a field of computational methods in which systems learn patterns or relationships from data to make predictions, decisions, or other outputs.
- compositionuses · Composition is the construction of a larger behavior, computation, or system by combining smaller functions, components, or operations.
Questions about strategy pattern
What is strategy pattern?
The Strategy pattern is a design pattern that encapsulates interchangeable algorithms or behaviors behind a common interface so they can be selected independently of their users.
Which Manning books explain strategy pattern?
Software Design for Python Programmers, Object-Oriented Software Design in C++, Microservices Patterns, Second Edition and Data-Oriented Programming in Java.
What should I know before learning strategy pattern?
Manning books that teach strategy pattern usually introduce accessor method, design pattern, enum and inheritance first.
What is the difference between strategy pattern and abstract factory design pattern?
The Strategy pattern is a design pattern that encapsulates interchangeable algorithms or behaviors behind a common interface so they can be selected independently of their users. The Abstract Factory is a creational design pattern that provides an interface for creating families of related objects without specifying their concrete classes.
What is strategy pattern a kind of?
Strategy pattern is a kind of pattern. A pattern is a reusable approach to solving a recurring problem within a particular context.
What is strategy pattern also called?
Strategy pattern is also called strategy design pattern.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



