← CS Visual Lab · Design Patterns

♟️ Strategy

💡 The ideaPut each algorithm in its own class behind one interface, and choose one at run time. Removes long if/else chains.
🏠 In real lifeGoogle Maps: the same trip, but you pick the strategy: car, bike, bus or walk.

🎬 Watch it work

Step 1 of 4
The interface

Every strategy has the same method.

interface Discount { apply(total: number): number }

✅ Check yourself (2 of 3 to pass)

1. Strategy mainly replaces:
2. Strategy follows which SOLID principle most directly?
3. The class that uses a strategy is called the:
Next: Adapter →Get a free certificate in Design Patterns