Multiple Inheritance &
Mixins

Recap

  • inheritance/OOP
  • super()
  • __dunders__
  • name mangling
  • setattr/getattr
  • @classmethod

Multiple Inheritance

Going deeper in inheritance

  • MRO (Method Resolution Order)
  • Python uses C3 Linearization to build it's MRO
  • Foo.mro()
  • dir(foo)
  • More on MRO and C3:
    • https://medium.com/technology-nineleaps/python-method-resolution-order-4fd41d2fcc
    • https://www.programiz.com/python-programming/multiple-inheritance#multilevel

Mixins conception

  • Another level of abstraction
  • Python's "interfaces"
  • Why should I use it?
    • You want to have a feature that all inheritors have
    • You want to have a feature that some of the inheritors have
  • Mixins are usually described as being included rather than being inherited

Multiple Inheritance & Mixins

By Hack Bulgaria

Multiple Inheritance & Mixins

Programming 101 with Python / 2019 week 05

  • 1,095