Strategy-mönstret definierar en familj av utbytbara algoritmer/beteenden, kapslar in var och en, och gör dem utbytbara vid körning. Det låter dig välja en algoritm dynamiskt och undvika komplexa villkor, vilket främjar flexibel, utvidgbar kod.
Vad Strategy-mönstret gör
STRATEGY → encapsulate INTERCHANGEABLE algorithms/behaviors behind a common interface:
→ define a family of strategies (each implements the same interface)
→ the context uses a strategy via the interface → can SWAP strategies at runtime
→ choose the behavior dynamically without changing the context
→ "compose" behavior instead of hardcoding it (favor composition over conditionals)
