ByteMonk logoByteMonk

System Design · Design Patterns

The Strategy Pattern: Kill Your If-Else Ladders

The pattern behind every pluggable behavior: payment methods, spot assignment, ranking algorithms. Learn the shape, the code, and when NOT to use it.

4 min read · design-patterns · strategy · lld

Every LLD interview eventually reaches the same moment: a behavior that varies. Payment can be card, UPI, or wallet. Parking spots can be assigned nearest-first or cheapest-first. Feeds can be ranked by recency or relevance. Reach for if-else and you've told the interviewer everything they need to know. Reach for Strategy and the conversation changes.

The shape

Strategy has three parts: a context that needs a behavior, an interface that names the behavior, and concrete strategies that implement it. The context never knows which concrete strategy it holds. That's the entire trick.

CheckoutServicepay(order)«interface»PaymentStrategyuses ▸CardPaymentUpiPaymentWalletPayment
Strategy: the context depends on the interface; implementations plug in from outside.

members only

This lesson is for members

Already a member? Sign in with your email and password and this lesson unlocks instantly.

Sign in →
like?