class Bulider: def __init__(self): pass def wheel(self): pass def engine(self): pass def frame(self): pass def getCar(self): pass class Car: def wheel(self): return ('这是轮子') def engine(self): return ('这是发动机') def frame(self): return ('这是车架') class BMWBuilder(Bulider): car = Car() str = '' def wheel(self): self.str += self.car.wheel() + " " def engine(self): self.str += self.car.engine() + " " def frame(self): self.str += self.car.frame() + " " def show(self): print(self.str) """ 指挥者调度 """ class Director: def __init__(self, BuildObj): BuildObj.wheel() BuildObj.wheel() BuildObj.wheel() BuildObj.wheel() BuildObj.engine() BuildObj.frame() class Client: car = Car() builder = BMWBuilder() director = Director(builder) builder.show()