Strategy પેટર્ન એક પરિવાર વ્યાખ્યાયિત કરે છે જે બદલી શકાય તેવા અલ્ગોરિધમ્સ/વર્તણૂકો, દરેકને encapsulates કરે છે, અને તેમને runtime પર બદલી શકાય તેવી બનાવે છે. આ તમને અલ્ગોરિધમ ગતિશીલ રીતે પસંદ કરવા દે છે અને જટિલ શરતી વિધાનો ટાળવા દે છે, લવચીક, વિસ્તૃત કોડને પ્રોત્સાહન આપે છે.
Strategy પેટર્ન શું કરે છે
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)
