Implementing Interfaces
Implementing Interfaces
π¨βπΌ Let's build a payment system with different payment methods. We'll use
interfaces to ensure all payment methods follow the same contract.
π¨ Open
and:
- Create a
PaymentMethodinterface with apay(amount: number)method - Create a
CreditCardclass that implementsPaymentMethod - Create a
PayPalclass that implementsPaymentMethod - Each class should have its own implementation of
pay()
π° Classes that implement an interface must define all its methods.