OOP & Design Patterns - Strategy Pattern - Replace Conditionals with Polymorphism
Consider the following Python code implementing the Strategy Pattern for payment processing:
What will be the output when the last line is executed?
class PaymentStrategy:
def pay(self, amount):
pass
class CreditCardStrategy(PaymentStrategy):
def pay(self, amount):
print(f"Paid ${amount} using Credit Card")
class PaymentProcessor:
def __init__(self, strategy):
self.strategy = strategy
def pay(self, amount):
self.strategy.pay(amount)
processor = PaymentProcessor(CreditCardStrategy())
processor.pay(100)What will be the output when the last line is executed?
