Abstract Base Classes
Discover how to define and use abstract base classes in Python's object-oriented programming using the abc module. Understand the role of abstract methods, the ABCMeta metaclass, and decorators like @abstractmethod to enforce method implementation in subclasses. Learn techniques to prevent instantiation of incomplete classes and explore class registration with decorators to control subclass behavior.
We'll cover the following...
It is mandatory for a derived class to implement methods of a base class. In this lesson, we’ll see how the Python built-in abc module facilitates it.
Introduction
A class that contains one or more than one abstract method is called an abstract class. An abstract method is declared, but isn’t implemented. The abc module in the Python library provides the infrastructure for defining custom abstract base classes as sometimes it’s not possible to instantiate a base class.
This ...