- 模式特点:将一个复杂对象的构建(Director)与它的表示(Builder)分离,使得同样的构建过程可以创建不同的表示(ConcreteBuilder)。
- 程序实例:“画”出一个四肢健全(头身手腿)的小人
- 代码特点:无
class Person:
def create_head(self):
pass
def create_hand(self):
pass
def create_body(self):
pass
def create_foot(self):
pass
class ThinPerson(Person):
def create_head(self):
print("thin head")
def create_hand(self):
print("thin hand")
def create_body(self):
print("thin body")
def create_foot(self):
print("thin foot")
class ThickPerson(Person):
def create_head(self):
print("thin head")
def create_hand(self):
print("thin hand")
def create_body(self):
print("thin body")
def create_foot(self):
print("thin foot")
class Director:
def __init__(self, temp):
self.p = temp
def create(self):
self.p.create_head()
self.p.create_hand()
self.p.create_body()
self.p.create_foot()
if __name__ == "__main__":
p = ThickPerson()
d = Director(p)
d.create()