Strategy pattern ਇੱਕ ਪਰਿਵਾਰ ਦੀ interchangeable algorithms/behaviors ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ, ਹਰੇਕ ਨੂੰ encapsulate ਕਰਦਾ ਹੈ, ਅਤੇ ਉਹਨਾਂ ਨੂੰ runtime ਤੇ swappable ਬਣਾਉਂਦਾ ਹੈ। ਇਹ ਤੁਹਾਨੂੰ ਇੱਕ algorithm ਨੂੰ dynamically ਚੁਣਨ ਦਿੰਦਾ ਹੈ ਅਤੇ complex conditionals ਤੋਂ ਬਚਦਾ ਹੈ, flexible, extensible code ਨੂੰ promote ਕਰਦਾ ਹੈ।
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)
