liveBook · Manning

Strategy pattern

As explained in Microservices Patterns, Second Edition

The Strategy pattern is an object-oriented design pattern that encapsulates interchangeable algorithms behind a common interface.

The Strategy pattern encapsulates an algorithm behind an interface so a class can use different concrete strategies for different contexts. section 7.6.1

A class-based Strategy design has three parts:

  • A strategy interface that encapsulates the algorithm. section 7.6.1
  • One or more concrete strategy classes, each for a particular context. section 7.6.1
  • A class that uses the algorithm through the strategy. section 7.6.1

Bank overdraft policies

A banking application can use an Overdraft interface, concrete policies for different limits and fees, and an Account class that uses the selected policy. section 7.6.1

How Microservices Patterns, Second Edition covers it

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.
How it connects
Connects the Strategy pattern to object-oriented design patterns and class-based solutions.

Also explained in

Compare how 4 books explain strategy pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.