Abstract Base Classes

Abstract base classes complement duck-typing by providing a way to define interfaces when other techniques like hasattr() would be clumsy or subtly wrong (for example with magic methods).

Protocol classes provide a support for structural subtyping (static duck typing).

Tutorials

  1. Protocol Or ABC In Python - When to use which one?

References

  1. Abstract Base Classes

  2. PEP 544 – Protocols: Structural subtyping

  3. Protocols and structural subtyping

  4. typing.Protocol

  5. Building Implicit Interfaces in Python with Protocol Classes

  6. Abstract Base Classes in Python: Fundamentals for Data Scientists

  7. Implementing an Interface in Python

  8. The ‘ABC’ of Abstract Base Classes