Back to Academy
oop
Interfaces & Abstract Classes
Interfaces and abstract classes define contracts that concrete classes must implement, ensuring consistent structure across different types. Like how every electrical outlet in a country follows the same plug standard — any appliance that matches the interface will work. Abstract classes can additionally provide shared base logic, while interfaces (or protocols in Python) enforce pure structure.
Use Cases
- •Defining a PaymentGateway interface that Stripe, PayPal, and crypto processors all implement
- •Creating an abstract Repository class with shared caching logic and abstract query methods
- •Enforcing that all serializers implement serialize() and deserialize() methods
- •Building plugin systems where third-party code must conform to a defined contract
Implementation
Output
Click "Run Code" to see output...