Skip to content

Lesson 07 · Python

Object-Oriented Design: Inheritance, ABCs & Protocols

Share behavior with inheritance and super(), enforce contracts with abstract base classes, type by shape with Protocols - and know when composition is the better answer.

Prerequisites: Object-Oriented Design: Classes & Objects

Learning objectives
By the end of this lesson, you will be able to:
  • Write subclasses that override methods and cooperate with super()
  • Design contracts with abc.ABC and @abstractmethod
  • Explain duck typing and type by shape with typing.Protocol
  • Recognize the isinstance pitfalls that break duck-typed code
  • Choose between inheritance, ABCs, Protocols and composition