Python_建造者模式
时间:2021-07-01 10:21:17
帮助过:14人阅读
#!/usr/bin/python
# -*- coding:utf-8 -*-
#建造者基类
class PersonBuilder():
def BuildHead(self):
pass
def BuildBody(self):
pass
def BuildArm(self):
pass
def BuildLeg(self):
pass
#胖子
class PersonFatBuilder(PersonBuilder):
type = u'胖子'
def BuildHead(self): PRint u'构建%s的头' % self.type
def BuildBody(self):
print u'构建%s的身体' % self.type
def BuildArm(self):
print u'构建%s的手' % self.type
def BuildLeg(self):
print u'构建%s的脚' % self.type
#瘦子
class PersonThinBuilder(PersonBuilder):
type = u'瘦子'
def BuildHead(self):
print u'构建%s的头' % self.type
def BuildBody(self):
print u'构建%s的身体' % self.type
def BuildArm(self):
print u'构建%s的手' % self.type
def BuildLeg(self):
print u'构建%s的脚' % self.type
#指挥者
class PersonDirector():
pb = None;
def __init__(self, pb):
self.pb = pb
def CreatePereson(self):
self.pb.BuildHead()
self.pb.BuildBody()
self.pb.BuildArm()
self.pb.BuildLeg()
def clientUI():
pb = PersonThinBuilder()
pd = PersonDirector(pb)
pd.CreatePereson()
pb = PersonFatBuilder()
pd = PersonDirector(pb)
pd.CreatePereson()
return
if __name__ == '__main__':
clientUI();
以上就是Python_建造者模式的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!