Strategy pattern ایک خاندان کے قابلِ تبدیل الگورتھمز/رویوں کی تعریف کرتا ہے، ہر ایک کو encapsulate کرتا ہے، اور انہیں runtime پر قابلِ تبدیل بناتا ہے۔ یہ آپ کو ایک الگورتھم کو متحرک طور پر منتخب کرنے اور پیچیدہ شرائط سے بچنے دیتا ہے، لچکدار، قابلِ توسیع کوڈ کو فروغ دیتا ہے۔
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)
