Multiple Class Inheritance Question

Y

YoTuco

Does (can) an inheritance scheme like this have any adverse effects
(pitt-falls) for the App class inheriting class 'A' twice?

Thanx in advance for your input.

class A:
A_attr = 'A'
...
def A_methods(self):
...

class B(A):
def __init__(self):
...

class C(A):
def __init__(self):
...

class App(B,C):
def __init__(self):
B.__init__(self)
C.__init__(self)
...
 
A

Alan Gauld

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/
 
M

Michele Simionato

Andy Jewell said:
Read guildo's essay on new style classes - that explains it all.

In the 'old days' i.e. before Python 2.2.x the rules were different. Now
a
new algorithm is used which copes better with this. As I said, read the
essay (it's on www.python.org - just search for 'new style classes essay'
).

hth
-andyj

.... and in Python 2.3 the rule has changed again ...

http://www.python.org/2.3/mro.html

Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top