# Strategy Pattern

> Pick how a job is done while the program runs.

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** Strategy, Policy Pattern

## Think of it like

Think of it like picking how to get to school. Bike, bus or walk, you still end up at school.

## Definition

The strategy pattern lets you swap one way of doing a job for another. It can happen while the program runs. Each way, or strategy, sits in its own small piece of code with the same shape. The main code is handed a strategy and simply calls it. To add a new way, you write a new strategy and leave the main code alone. In many languages, passing a function is the simplest form of it.

## Example

Emma's shop works out shipping three ways: standard, express and pickup. Checkout is handed the one the buyer picked and calls it, with no long if-else chain.

## Why it matters

It replaces long chains of if and else with small parts that are easy to test and add to.

## Common mistake

Building classes for two choices that never change. A simple if is clearer until there are more.

## Three principles

- **Same shape.** Many ways to do it.
- **Swap at run time.** Pick the one you need.
- **Add without editing.** Main code stays put.

## Related terms

- [Design Pattern](https://learn.benibix.com/term/development/design-pattern)
- [Conditional Statement](https://learn.benibix.com/term/development/conditional-statement)
- [Factory Pattern](https://learn.benibix.com/term/development/factory-pattern)
- [SOLID Principles](https://learn.benibix.com/term/development/solid-principles)

---

Source: https://learn.benibix.com/term/development/strategy-pattern
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
