Leon Mak c8a481bb77 Add java 11 support for #987 (o-t) (#1051)
* Use java 11

* Use .of
- Replace Arrays.asList with List.of
- Replace HashSet<>(List.of()) with Set.of

* Formatting
2019-10-29 08:37:40 +02:00
..
2017-11-28 20:55:52 +02:00
2019-10-12 20:05:54 +03:00
2018-01-28 14:44:19 -05:00

layout, title, folder, permalink, categories, tags
layout title folder permalink categories tags
pattern Strategy strategy /patterns/strategy/ Behavioral
Java
Difficulty-Beginner
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.

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