How to order base classes?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Dec 23 23:25:01 EST 2010
On Fri, 24 Dec 2010 03:36:28 +0000, kj wrote:
> How should one go about deciding the ordering of base classes?
There is no general way for doing so. You need to consider the actual
functionality of the methods involved. Consider a method spam() of class
C that inherits from both A and B. To be completely general, you might
have any of the following situations:
C.spam() overloads A.spam() followed by B.spam()
C.spam() overloads B.spam() followed by A.spam()
C.spam() overloads A.spam() and overrides B.spam()
C.spam() overloads B.spam() and overrides A.spam()
C.spam() overrides both A.spam() and B.spam()
(where I use "overload" to mean "modify the behaviour of", and "override"
to mean "change the behaviour completely" -- basically, overloading will
call the superclass' method, while overriding will not.)
And (again, we're being completely general) whatever choice you make for
C.spam() may not be valid for C.ham(), which could behave completely
differently.
The question you ask can only be answered in reference to a specific
class with specific methods. There is no general principle, it depends
entirely on the problem being solved.
--
Steven
More information about the Python-list
mailing list