-- 基础类方法 new functionShape.new(self, o, side) o = o or {} setmetatable(o, self) self.__index = sself side = side or {} self.data = side * side return o end
-- 基础类方法 printarea functionShape:printarea() print("shape are is: ", self.area) end
-- 派生类方法 new functionRectangle.new(self, o, length, breadth) o = o or Shape:new(o) setmetatable(o, self) self.__index = self self.area = length * breadth return o end
-- 派生类方法 printarea functionRectangle:printarea() print("rectangle area is ", self.area) end