6.1. Inheritance About

  • no inheritance

  • single inheritance

  • linear inheritance

  • multiple inheritance (mixin classes)

single inheritance

One class inherits from one other class. Has one parent.

linear inheritance

One class inherits from other class, and yet another class inherits from it. This creates hierarchical structure.

multiple inheritance
mixin classes

One class derives from several other classes at once.

6.1.1. No Inheritance

>>> class User:
...     pass
>>>
>>> class Admin:
...     pass
../../_images/inheritance-patterns-no.png

6.1.2. Single Inheritance

>>> class User:
...     pass
>>>
>>> class Admin(User):
...     pass
../../_images/inheritance-patterns-single.png

6.1.3. Linear Inheritance

>>> class Account:
...     pass
>>>
>>> class User(Account):
...     pass
>>>
>>> class Admin(User):
...     pass
../../_images/inheritance-patterns-linear.png

6.1.4. Multiple Inheritance

>>> class User:
...     pass
>>>
>>> class Admin:
...     pass
>>>
>>> class Account(User, Admin):
...     pass
../../_images/inheritance-patterns-multiple.png