Skip to main content
Practice Problems

What is Strategy design pattern?

javascript
// Different payment strategies class PayPalPayment { pay(amount) { console.log(`Paid ${amount} via PayPal`); } } class CreditCardPayment { pay(amount) { console.log(`Paid ${amount} via Credit Card`); } } class CryptoPayment { pay(amount) { console.log(`Paid ${amount} via Crypto`); } } // Context uses strategy class PaymentProcessor { constructor(strategy) { this.strategy = strategy; } process(amount) { this.strategy.pay(amount); } } // Usage - choose strategy at runtime const processor = new PaymentProcessor(new PayPalPayment()); processor.process(100);

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems