Payment Processing with Polymorphism

Create a class Payment with a method process(). Extend this class into CreditCardPayment and DebitCardPayment, each implementing the process() method appropriately.

Example 1:

Input: CreditCardPayment 
Output: "Processing credit card payment"

Example 2:

Input: DebitCardPayment
Output: "Processing debit card payment"

Override the process() method in each subclass to return the processing method for the payment.

class Payment:
    def process(self):

class CreditCardPayment(Payment):
    def process(self):
        return "Processing credit card payment"

class DebitCardPayment(Payment):
    def process(self):
        return "Processing debit card payment"

# Test the classes
credit_card_payment = CreditCardPayment()
print(credit_card_payment.process())  # Output: Processing credit card payment

debit_card_payment = DebitCardPayment()
print(debit_card_payment.process())  # Output: Processing debit card payment

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!