---
# System prepended metadata

title: Strategy Pattern

---

# Strategy Pattern


One day you decided to create a navigation app for casual travelers...

most important function is automatic route planning
at the beginning -> automatic route planning for **car**
next update -> you added an option to build **walking** routes
next update -> you added an option to build routes for **cyclists**

then The code of the navigator became bloated.
![](https://i.imgur.com/CEDavS1.jpg)


![](https://i.imgur.com/fWIvrSV.jpg)
![](https://i.imgur.com/77tYa6P.jpg)

![](https://i.imgur.com/XXKKCYO.jpg)


## Applicability

1.  Use the Strategy pattern when you want to use different variants of an algorithm within an object and be able to **switch from one algorithm to another during runtime**.
2.  Use the Strategy **when you have a lot of similar classes that only differ in the way they execute some behavior**.
3.  Use the pattern to **isolate the business logic** of a class from the implementation details of algorithms that may not be as important in the context of that logic.
4.  Use the pattern when your class has a massive conditional statement that switches between different variants of the same algorithm.
