class Thing(object):
def sound(self):
return '' #Silent
class Animal(Thing):
def sound(self):
return 'Roar!'
class MuteAnimal(Animal):
def sound(self):
return '' #Silent
python中是否有一个模式用于MuteAnimal
的声音引用其祖父母类Thing
的实现?(例如super(MuteAnimal,self).super(Animal.self).sound()
?)或者Mixin是一个更好的用例?在
正如Alexander Rossa在 Python inheritance - how to call grandparent method?:
这样做明智吗?在
在
MuteAnimal.sound
中,调用super(Animal, self).sound()
因为动物实际上是互斥动物的父类。。。在
相关问题 更多 >
编程相关推荐