Inheritance but only partly?
Gary Herron
gherron at islandtraining.com
Thu Oct 2 16:46:56 EDT 2008
Gary Herron wrote:
> process wrote:
>
>> Let's say I have a class X which has 10 methods.
>>
>> I want class Y to inherit 5 of them.
>>
>> Can I do that? Can I do something along the lines of super(Y, exclude
>> method 3 4 7 9 10) ?
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
> No.
>
> But why do yo care? You can just ignore the 5 you don't want -- their
> existence costs you nothing in either memory or execution speed.
>
> You can also redefine the ones you don't want inherited:
>
> class A:
> def DontInheritMe(self, ...):
> ...
>
> Class B(A):
> def DontInheritMe(self, ...):
> raise NotImplementedError // Or some such
>
>
> Gary Herron
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Here's another (very Python) possibility
class Base:
class m1(self, ...):
...
class m2(self, ...):
...
class NotInheritable:
class m3(self, ...):
...
class A(Base, NotInheritable);
...
class B(Base):
...
More information about the Python-list
mailing list