OOP & Design Patterns - Strategy Pattern - Replace Conditionals with Polymorphism
Identify the bug in the following code snippet implementing the strategy pattern for payment processing:
class PaymentProcessor:
def __init__(self, strategy: PaymentStrategy):
self.strategy = strategy
def pay(self, amount):
if isinstance(self.strategy, CreditCardStrategy):
print(f"Processing credit card payment of ${amount}")
elif isinstance(self.strategy, UPIStrategy):
print(f"Processing UPI payment of ${amount}")
else:
print("Invalid payment method")
