|
From: <bc...@wo...> - 2001-08-13 19:24:40
|
[Kevin Butler] >[...] > >So multiple inheritance seems the right way to approach this (it gives >you the ghosting feature, all the multiple inheritance/mixins features, >and does it in established Python syntax). > >Early versions of jpython allowed multiple inheritance of Java classes. >Later versions disabled it explicitly, mostly because it wasn't supported >in jpythonc. I'm not at all sure that was the main motivation. >I believe this was a mistake, but I have yet to put my code >where my mouth is, so I should probably shut up about it. But here goes >anyway. :-) > >Ideally, Python code should not care whether a class instance is implemented >in Python or in Java (or C...), including when you try to inherit from it. Wrong ideal IMO. As long as java classes and instance can be used and created from jython, I don't mind this kind to semantic differences. >I haven't investigated the code, but I expect it wouldn't be hard to re-enable. > >Here's the FAQ entry that talks about it the history: >http://www.jython.org/cgi-bin/faqw.py?req=show&file=faq03.001.htp > >This links to: http://mail.python.org/pipermail/jpython-interest/1998-April/000213.html >and a bad link, that should probably be replaced with: Fixed. Thanks. >I'd propose that we allow the multiple inheritance behavior, and make jythonc >encode that behavior in some rational way based on delegation (multiple >inheritance in Python doesn't _have_ to make to inheritance in Java, >otherwise we couldn't implement Python on the JVM). Well, I still can't see a big need for MI. >This makes jythonc's job a bit harder - but only for classes that use multiple inheritance. > >The basic approach would be to have the derived class implementation inherit from the _first_ base class. Any other "base classes" become a contained member as shown below. This lets single inheritance generate exactly the code it does today, and supports multiple inheritance in a reasonable way. > >Issues (and suggestions): > >- access to protected methods/data of base classes (not needed, because Jython doesn't support it) >- derived methods delegating to base classes (provide 'super_method' that calls super.method) >- base class methods that call derived methods - template method pattern (derived method delegates to method on combined class) >- methods with the same name in two base classes (delegate to method on combined class) >- methods of X that access both A and B (delegate to method on combined class) >- data members with the same name in two base classes (really painful - maybe leave that as a restriction in jythonc?) > >class X( A, B, C ): > def MyCMethod( self ): > # do stuff, then > return C.MyCMethod( self ) > >becomes: > >public class X extends A I assume that that X, B_X a C_X all implements PyProxy. >{ > public X( args ) > { > super( a_args ); > b = new B_X( this, b_args ); > c = new C_X( this, c_args ); Keep in mind that the X.__init__ method may call the A, B and C __init__ method at different time with different arguments. The B_X and C_X instances can't be created at the same time as the A instance. Instead a reference to the B_X and C_X instances can be stored in the PyInstance where a reference to the X instance is stored already. >[...] regards, finn |