Strategy pattern ले अदलाबदल गर्न सकिने algorithms/behaviors को एक परिवार परिभाषित गर्छ, प्रत्येकलाई encapsulate गर्छ, र यसलाई runtime मा स्वैप गर्न सकिने बनाउँछ। यसले तपाईंलाई algorithm लाई गतिशीलरूपमा चयन गर्न र जटिल conditionals बचाउन दिन्छ, flexible, extensible कोड लाई बढावा दिन्छ।
Strategy pattern ले के गर्छ
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)
