Motivation
Strategy is the single most common pattern in LLD interviews. Whenever you see conditional logic based on type, then that’s a strategy pattern waiting to happen. Strategy replaces conditional logic with polymorphism.
Sample Code
public interface IPaymentStrategy
{
bool Pay(double amount);
}
public class CreditCardPayment(string cardNumber) : IPaymentStrategy
{
public bool Pay(double amount) { ... }
}
public class PayPalPayment(string email) : IPaymentStrategy
{
public bool Pay(double amount) { ... }
}
public class ShoppingCart
{
private IPaymentStrategy? _paymentStrategy;
public void SetPaymentStrategy(IPaymentStrategy strategy) { ... }
public void Checkout(double amount) { _paymentStrategy?.Pay(amount); }
}
… where ShoppingCart.Checkout doesn’t have clauses like if (paymentType == "credit") { ... }.
References
- Design Patterns | Hello Interview Low Level Design. www.hellointerview.com . Accessed Oct 3, 2026.