#学习版本3.5.2
#建造者模式,固定生产过程用来生产同一类产品
#例如:工厂生产高级车和普通车
class CreateCar(object):
def createWheel(self):
pass
def createCarBody(self):
pass
def create(self):
pass
class CreateHighCar(CreateCar):
def createWheel(self):
print("create high level wheel")
def createCarBody(self):
print("create high level car body")
def create(self):
self.createWheel()
self.createCarBody()
print("complete high level car")
class CreateNormalCar(CreateCar):
def createWheel(self):
print("create normal wheel")
def createCarBody(self):
print("create normal car body")
def create(self):
self.createWheel()
self.createCarBody()
print("complete normal car")
if __name__ == "__main__":
cc1 = CreateHighCar()
cc1.create()
cc2 = CreateNormalCar()
cc2.create()
运行结果
create high level wheel
create high level car body
complete high level car
create normal wheel
create normal car body
complete normal car