我有以下兩類:功能沒有被覆蓋的子類
class Shape(object):
def __init__(self, start_point, *args):
self.vertices = []
self.__make_vertices(start_point, *args)
def __make_vertices(self, start_point, *args):
print "Not Implemented: __make_vertices"
def __getitem__(self, *args):
return self.vertices.__getitem__(*args)
class Cube(Shape):
def __init__(self, start_point, side_length):
Shape.__init__(self, start_point, side_length)
def __make_vertices(self, start_point, side_length):
append = self.vertices.append
start_point = Vector(*(start_point))
i, j, k = side_length*I, side_length*J, side_length*K
append(start_point)
append(self.vertices[-1] - k)
append(self.vertices[-1] - j)
append(self.vertices[-1] + k)
append(self.vertices[-1] - i)
append(self.vertices[-1] - k)
append(self.vertices[-1] + j)
append(self.vertices[-1] + k)
print self.vertices
當我提出一個新的Cube
,我期望我在多維數據集類中定義的__make_vertices
函數將被調用,而是我一直獲取Shape
類__make_vertices
函數打印出的消息。我誤解了什麼?
http://php.net/manual/en/language.oop5.overloading.php – 2013-12-22 18:00:25
@Allendar:這是Python,而不是PHP。 – BrenBarn
對不起,我在筆記本電腦後面睡着了,嘿嘿,我的壞:) – 2013-12-22 18:04:49