Search⌘ K

Abstract Base Classes

Explore how abstract base classes in Python enforce method implementation in child classes, preventing inappropriate instantiation and supporting polymorphism. Understand their use to create clear, reliable OOP designs by combining the abc module and @abstractmethod decorator.

What are Abstract Base Classes?

Duck typing is useful as it simplifies the code and the user can implement the functions without worrying about the data type. But this may not be the case all the time. The user might not follow the instructions to implement the necessary steps for duck typing. To cater to this issue, Python introduced the concept of abstract base classes, or ABC.

Abstract base classes define a set of methods and properties that a class must implement in order to be considered a duck-type ...