liveBook · Manning

Strategy pattern

Also called strategy 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.

How 4 Manning books explain it

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

What to know first

Related concepts

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.