Strategy पैटर्न परस्पर विनिमेय एल्गोरिदम/व्यवहारों का एक परिवार परिभाषित करता है, प्रत्येक को encapsulate करता है, और उन्हें रनटाइम पर अदला-बदली करने योग्य बनाता है। यह आपको गतिशील रूप से एक एल्गोरिदम चुनने और जटिल कंडीशनल से बचने देता है, जिससे लचीला, विस्तार योग्य कोड को बढ़ावा मिलता है।
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)
