liveBook · Manning

Strategy design pattern

The Strategy design pattern encapsulates interchangeable algorithms or behaviors behind a common interface so they can be selected independently of the code that uses them.

How 2 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 design 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 design pattern →

Related concepts

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.