Abstract base classes (ABCs) are like small building blocks for creating a higher level of abstraction. They allow you to implement really usable interfaces, but are very generic and designed to handle a lot more than this single design pattern. You can unleash your creativity and do magical things, but building something generic and really usable may require a lot of work. Work that may never pay off.
This is the reason custom abstract base classes are not used so often. Despite that, the collections.abc module provides a lot of predefined ABCs that allow for compatibility of types with common Python interfaces. With the base classes provided in this module, you can check, for example, whether a given object is callable, mapping, or whether it supports iteration. Using them with the isinstance() function is way better than comparing against the base Python types. You should definitely know how to use these base classes even if you don't want to define your own custom interfaces with ABCMeta.
The most common abstract base classes from the collections.abc that you will use from time to time are as follows:
- Container: This interface means that the object supports the in operator and implements the __contains__() method.
- Iterable: This interface means that the object supports the iteration and implements the __iter__() method.
- Callable: This interface means that it can be called like a function and implements the __call__() method.
- Hashable: This interface means that the object is hashable (that is, it can be included in sets and as key in dictionaries) and implements the __hash__ method.
- Sized: This interface means that the object has size (that is, it can be a subject of the len() function) and implements the __len__() method.
A full list of the available abstract base classes from the collections.abc module is available in the official Python documentation (refer to https://docs.python.org/3/library/collections.abc.html).