Abstract base classes
The core of the Abstract Base Class (ABC) definition is defined in a module named abc
. This contains the required decorators and metaclasses to create abstractions. Other classes rely on these definitions.
In Python 3.2, the abstract base classes for collections were buried in collections
. In Python 3.3, however, the abstract base classes have been split into a separate submodule named collections.abc
.
We'll also look at the numbers
module, because it contains ABCs for numeric types. There are abstract base classes for I/O in the io
module too.
We'll focus on Python Version 3.3. The definitions will work very similarly for Python 3.2, but the import
statement will change slightly to reflect the flatter library structure.
An abstract base class has a number of features, as follows:
Abstract means that these classes don't contain all of the method definitions required to work completely. For it to be a useful subclass, we will need to provide some method definitions.
Base means...