Inheritance but only partly?
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Thu Oct 2 18:11:12 EDT 2008
Gary Herron:
> 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
I have never used something like this, but the OP may use a masking
class too:
class A(object):
def m1(self): pass
def m2(self): pass
def m3(self): pass
def m4(self): pass
class Mask(object):
def m3(self): raise NotImplementedError
def m4(self): raise NotImplementedError
class B(Mask, A):
pass
a = A()
a.m1()
a.m2()
a.m3()
a.m4()
b = B()
b.m1()
b.m2()
b.m3() # raises
b.m4() # raises
In a language without multiple inheritance you need a different trick,
I presume.
What's the name of this python design pattern? :-)
Bye,
bearophile
More information about the Python-list
mailing list