Connecting Tech Pros Worldwide Forums | Help | Site Map

Multiple Class Inheritance Question

YoTuco
Guest
 
Posts: n/a
#1: Jul 18 '05
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)
...


Alan Gauld
Guest
 
Posts: n/a
#2: Jul 18 '05

re: Multiple Class Inheritance Question


On Sun, 13 Jul 2003 19:28:15 GMT, YoTuco <not.valid@address.org>
wrote:
[color=blue]
> Does (can) an inheritance scheme like this have any adverse effects
> (pitt-falls) for the App class inheriting class 'A' twice?
>[/color]
[color=blue]
> class App(B,C):
> def __init__(self):
> B.__init__(self)
> C.__init__(self)[/color]

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/
Michele Simionato
Guest
 
Posts: n/a
#3: Jul 18 '05

re: Multiple Class Inheritance Question


Andy Jewell <andy@wild-flower.co.uk> wrote in message news:<mailman.1058131417.23876.python-list@python.org>...[color=blue]
> 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[/color]

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

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

Michele
Michael Hudson
Guest
 
Posts: n/a
#4: Jul 18 '05

re: Multiple Class Inheritance Question


mis6@pitt.edu (Michele Simionato) writes:
[color=blue]
> Andy Jewell <andy@wild-flower.co.uk> wrote in message news:<mailman.1058131417.23876.python-list@python.org>...[color=green]
> > 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[/color]
>
> ... and in Python 2.3 the rule has changed again ...
>
> http://www.python.org/2.3/mro.html[/color]

Though not so much as to change the MRO in this situation.

Cheers,
M.

--
FORD: Just pust the fish in your ear, come on, it's only a
little one.
ARTHUR: Uuuuuuuuggh!
-- The Hitch-Hikers Guide to the Galaxy, Episode 1
Closed Thread


Similar Python bytes