← 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 }