نمط Strategy يعرّف عائلة من الخوارزميات/السلوكيات القابلة للتبديل، ويغلّفها، ويجعلها قابلة للتبديل في وقت التشغيل. يسمح لك باختيار خوارزمية بشكل ديناميكي وتجنب الشروط المعقدة، مما يعزز كود مرن وقابل للتوسع.
ما يفعله نمط 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)
