LLD - Design — Online Shopping Cart
Given the following code snippet implementing the Payment Strategy Pattern, what will be the output?
class PaymentStrategy {
pay(amount) { throw 'Not implemented'; }
}
class CreditCardPayment extends PaymentStrategy {
pay(amount) { return `Paid ${amount} with Credit Card`; }
}
class PayPalPayment extends PaymentStrategy {
pay(amount) { return `Paid ${amount} with PayPal`; }
}
class PaymentContext {
constructor(strategy) { this.strategy = strategy; }
executePayment(amount) { return this.strategy.pay(amount); }
}
const context = new PaymentContext(new PayPalPayment());
console.log(context.executePayment(100));