Multiple Class Inheritance Question
Alan Gauld
alan.gauld at btinternet.com
Sun Jul 13 18:01:38 EDT 2003
On Sun, 13 Jul 2003 19:28:15 GMT, YoTuco <not.valid at address.org>
wrote:
> Does (can) an inheritance scheme like this have any adverse effects
> (pitt-falls) for the App class inheriting class 'A' twice?
>
> class App(B,C):
> def __init__(self):
> B.__init__(self)
> C.__init__(self)
The way you wrote it no since neither B nor C called A's init
method! But assuming they did then there are obvious potential
problems in calling any method twice. For instance if it modifies
an external global value it will be modified twice... If it
modifies a class value similarly it will be modified twice. But
because those are "obvious" issues the designer can work around
them...
In the case of calling methods implemented by A and inherited by
B or C there is no such problem since the message search
algorithm stops when it finds an implementation so it will only
ever call the method once. Provided you make sure the order
of B,C in the inheritance list is right fo you then it should be
OK. (Recall that App(B,C) is not the same as App(C,B) )
HTH,
Alan G.
Alan g.
http://www.freenetpages.co.uk/hp/alan.gauld/
More information about the Python-list
mailing list