Part 1 of 6 · 1 min read
Why this page comes first in Level 4
In this module you will
- State the Strategy pattern and name its three parts.
- Replace an
iforswitchover "which way" with strategy objects. - Swap a strategy at run time, and say when that is useful.
- Use a Java lambda as a one-method strategy.
- List the costs: more objects, and clients that must choose.
Level 3 covered who creates objects. Level 4 covers how objects work together, and strategy is the most used pattern in design rounds. It is the practical form of the open-closed principle (Level 2, module 2). The sources are "Design Patterns" (GoF) chapter 5 and "Head First Design Patterns" (HF) chapter 1. Code was compiled and run before it was written here. Numbers marked "made up" only show the idea.