iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
An if/else becomes a good candidate for the Strategy pattern when its branches are interchangeable ways to perform the same job, and those alternatives change or multiply enough that keeping them together makes the code harder to understand or maintain. There is no branch-count threshold: a short, stable conditional is often clearer than a set of extra classes.
What makes a conditional a Strategy candidate?
Look at what the branches do, not how many there are. Strategy fits when each branch implements a different version of one algorithm, such as calculating a shipping cost or finding a route. The surrounding code can then delegate that job through a shared interface or callable boundary, while a caller or policy selects the implementation.
For example, road, walking, cycling, and public-transit route planning are different ways to solve the same route-building problem. A route planner can pass that work to whichever algorithm is appropriate. The pattern is useful because the alternatives share a role, not simply because the original code contains a conditional. Refactoring Guru’s Strategy overview describes this structure and route-planning example.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use change and cohesion—not branch count—as the test
A conditional is more likely to need refactoring when its alternatives are added or revised regularly, do the same kind of work in different ways, or require edits to a central class whenever one variant changes. A compact conditional for a small, stable set of cases may remain easier to follow.
#1 Best Overall
- EXPLORE THE ISLAND OF CATAN: Settle the uninhabited island of Catan by gathering resources, building infrastructure, and nurturing trade relationships.
- STRATEGY AND COMPETITION: Compete with 2-3 opponents to expand your settlements and cities while managing resources and avoiding the robber.
- TRADE, BUILD, AND SETTLE: Use brick, wood, wheat, ore, and sheep to construct roads, settlements, and cities in your race to 10 victory points.
- REPLAYABLE AND ENGAGING: With a modular hexagonal board, no two games are the same, offering endless strategic opportunities and replayability.
- FOR FAMILIES AND STRATEGY ENTHUSIASTS: Designed for 3-4 players, ages 10 and up, CATAN 6th Edition is perfect for family game nights and friendly competition. Add the CATAN 5-6 Player Extension (sold separately) to expand your game to 5-6 players.
Kai, writing on DEV Community, suggests that two or three types that rarely change can stay conditional. That is a practical rule of thumb, not a measured cutoff. As Kai puts it, “A pattern is a trade, not a trophy.” Kai’s DEV Community article uses shipping-cost calculation to illustrate the decision: as shipping rules become independently changing alternatives, each can implement the same calculation contract and the caller can delegate to the selected one.
Ask these questions before extracting a Strategy
- What varies? Are these interchangeable algorithms for one job, or several unrelated actions grouped together?
- How often does it change? Are new variants or rule changes common, or are the cases unlikely to move?
- Who should choose? Should a caller or policy select the behavior, or does the object’s own state determine it?
- Will the boundary pay for itself? Will naming and isolating each algorithm make the code easier to read and extend, or add indirection without a real benefit?
- What does the language make simplest? A function, lambda, or handler map may express the boundary more cleanly than a class hierarchy.
A practical way to refactor
- Keep the direct conditional first. Do not introduce a pattern solely to eliminate an
if/else. - Name the changing work. Extract the algorithm into a method so its purpose is visible and its callers are simpler.
- Introduce a strategy boundary when needed. If genuinely interchangeable implementations are changing independently and the conditional has become costly to modify, let the surrounding code delegate through a shared contract or callable.
- Keep selection explicit. Make it easy to find where the chosen strategy comes from; the pattern should clarify responsibility, not hide it.
This is a useful progression, not a universal rule. A simple conditional that selects parameters for the same method may be best left as-is or split into clearer methods.
Rank #2
- Stratego is the strategic game where you challenge your opponents in the heat of battle
- Your task is to capture your opponent’s flag while defending your own
- Lead your men into battle, every move is crucial
- Includes 2 x 40 pre-printed playing pieces, Game board, Screen and 2 sorting trays for the pieces
- Suitable for 2 players, aged 8+
Distinguish Strategy from State
Strategy is for choosing among interchangeable algorithms. State is for behavior that changes as an object’s internal condition changes, often affecting more than one isolated operation. The structures can look similar because both may delegate behavior to another object; the reason for delegation is different.
If a type code only chooses an algorithm, Strategy may fit. If that code represents the object’s broader condition and governs other actions or transitions, consider State instead. Refactoring Guru’s State overview explains the state-dependent model.
Rank #3
- EXCITING TRAIN ADVENTURE: Embark on a journey across early 20th century North America, collecting train cards and claiming routes to expand your network and connect cities.
- EASY TO LEARN, HARD TO MASTER: With simple rules and engaging gameplay, Ticket to Ride is perfect for both new and experienced players, making it a great choice for family game nights.
- BEAUTIFUL GAME COMPONENTS: Features a giant map of the North American train network, accompanied by miniature trains for each player, enhancing the visual appeal and immersive experience.
- MULTIPLE WAYS TO WIN: Strategically collect color sets of train cards, complete your tickets, and build the longest routes to secure victory, offering endless replayability.
- FUN FOR ALL AGES: Whether you're playing with family or friends, Ticket to Ride offers hours of fun, making it an ideal choice for casual and competitive gamers alike.
When polymorphism may be the better refactoring
If similar conditionals recur across methods or classes because behavior depends on an object’s type or properties, the behavior may belong with the relevant type. Replacing a conditional with polymorphism can help in that situation. It is not a reason to remove every switch: when cases merely select parameters for the same operation, polymorphism may add more structure than value. Refactoring Guru’s discussion of switch statements covers these alternatives.
Quick Recap
Rank #4
- CLASSIC TILE PLACEMENT: Draw and place landscape tiles to build cities, roads, fields, and monasteries, then deploy meeples as knights, farmers, and monks to claim features and score points.
- STRATEGY FOR ADULTS AND FAMILIES: Carcassonne pairs intuitive rules with meaningful decisions, making it accessible for ages 7+ while still engaging experienced adult board gamers.
- REPLAYABLE MEDIEVAL ADVENTURE: Randomized tile draws create a different landscape every game, bringing fresh puzzles and competitive fun to family game night and casual group play.
- TWO TO FIVE PLAYERS: Built for 2-5 players with an average 35-minute playtime, Carcassonne fits weeknight sessions at home, family gatherings on vacation, and adult board game evenings.
- INCLUDES MINI-EXPANSIONS: The base game comes with The Abbot and The River mini-expansions in the box, adding variety to the classic Carcassonne board game experience from the start.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

