我有一个基类,Python中得出几个:问题有关Python和类
class Base:
def Foo(self):
pass
# First derived class
class Der1(Base):
def OwnFoo(self):
# Do something 1
def OwnFoo2(self):
# Do something 2
def Foo(self):
# Do something 3
# Second derived class
class Der2(Base):
def OwnFoo(self):
# Do something 1
def OwnFoo2(self):
# Do something 2
def Foo(self):
# Do something 3
的问题是:
我在Der1
一些预定义的代码。从Der2
几乎所有的功能都一样。我怎样才能用更少的代码编写这个?
我无法将该代码添加到父级。不应该触摸父类。
例如,Der2.OwnFoo
不一样Der1.OwnFoo
,也许有一些建筑在Python只是从第一级呼叫OwnFoo
,而不是写一遍代码?
我无法改变的Der1
和Der2
父!它应该是Base
。
它是一门功课? – eumiro 2011-04-19 13:25:35