What are abstract base classes and protocols?

Python classes and OOP · Experienced

Model answer

An abstract base class (abc.ABC with @abstractmethod) cannot be instantiated until subclasses implement the abstract methods, enforcing an interface. A typing.Protocol defines an interface structurally for type checkers: any class with the right methods matches, with no inheritance needed.

Learn this topic

Classes and Objects in Python: A Gentle Introduction in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions