Wednesday, 4 February 2009

How Multiple Inheritance Works in Python

class Derived(Base1, Base2, Base3):
statement1
statement2

The resolution rule for class attribute references is as follows (depth-first left to right):
  1. if attribute not in Derived, check Base1. If not in Base1, recursively check base classes of Base1.
  2. if not in Base1, check Base2. und so weiter, und so weiter.

Mixin classes are classes designed to be combined with other classes via multiple inheritance. The Tkinter module uses mixins extensively (e.g. the Misc class used as a mixin by the root window and widget classes). Misc provides a large number of Tk and window related services.

No comments: