Glossary

Abstract Base Class

Also known as: ABC

An Abstract Base Class (ABC) is a class that cannot be instantiated directly and that defines one or more abstract methods — methods that subclasses must implement. In Python, ABCs are created by inheriting from abc.ABC and decorating methods with @abc.abstractmethod. Any attempt to instantiate a class that has unimplemented abstract methods raises TypeError.

ABCs serve as formal interfaces in Python. They say "any class that claims to be a Shape must implement area() and perimeter()." The standard library uses ABCs extensively in the collections.abc module: Iterable, Iterator, Sequence, Mapping, MutableMapping, and many others define the expected interfaces for Python's built-in collection protocols.

ABCs can also provide concrete methods — default implementations that subclasses inherit. They can register "virtual subclasses" that do not actually inherit from the ABC but are recognised by isinstance() and issubclass(). In modern Python, Protocols (from typing, PEP 544) provide an alternative approach to interface definition based on structural subtyping (duck typing) rather than inheritance, and are increasingly preferred for type-checking purposes.

Related terms: Inheritance, Protocol, Duck Typing

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.