Anurag Agarwal cd2a2e7711 Java 11 migrate all remaining s (#1120)
* Moves saga to Java 11

* Moves semaphore to Java 11

* Moves servant to Java 11

* Moves serverless to Java 11

* Moves service-layer to Java 11

* Moves service-locator to Java 11

* Moves sharding to Java 11

* Moves singleton to Java 11

* Moves spatial-partition to Java 11

* Moves specification to Java 11

* Moves state to Java 11

* Moves step-builder to Java 11

* Moves strategy to Java 11

* Moves subclass-sandbox to Java 11

* Fixes checkstyle issues
2020-01-04 18:36:08 +02:00
..
2019-12-07 18:03:49 +02:00
2019-12-29 14:41:21 +02:00

layout, title, folder, permalink, categories, tags
layout title folder permalink categories tags
pattern Strategy strategy /patterns/strategy/ Behavioral
Gang of Four

Also known as

Policy

Intent

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Class diagram

alt text

Applicability

Use the Strategy pattern when

  • Many related classes differ only in their behavior. Strategies provide a way to configure a class either one of many behaviors
  • You need different variants of an algorithm. for example, you might define algorithms reflecting different space/time trade-offs. Strategies can be used when these variants are implemented as a class hierarchy of algorithms
  • An algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex, algorithm-specific data structures
  • A class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move related conditional branches into their own Strategy class

Tutorial

Credits