Strategy pattern एक कुटुंब परस्पर-बदलण्यायोग्य अल्गोरिदम/वर्तनांची व्याख्या करते, प्रत्येकाला encapsulate करते, आणि त्यांना runtime वर स्वॅप करण्यायोग्य बनवते. हे तुम्हाला एक अल्गोरिदम डायनॅमिकली निवडू देते आणि जटिल conditionals टाळू देते, लचकदार, विस्तारित कोड प्रोत्साहित करते.
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)
