© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
V. SarcarJava Design Patternshttps://doi.org/10.1007/978-1-4842-7971-7_21

21. Strategy Pattern

Vaskaran Sarcar1  
(1)
Garia, Kolkata, India
 

This chapter covers the Strategy pattern. It is also known as the Policy pattern.

GoF Definition

It defines a family of algorithms, encapsulates each one, and makes them interchangeable. The Strategy pattern lets the algorithm vary independently from the clients that use it.

Concept

A client can select an algorithm from a set of algorithms dynamically at runtime. This pattern also provides a simple way to use the selected algorithm.

You know that an object can have states and behaviors. And some of these behaviors may vary among ...

Get Java Design Patterns: A Hands-On Experience with Real-World Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.