python

#!/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() returnif __name__ == ‘__main__’: clientui();

以上就是python_建造者模式的内容,更多相关内容请关注php中文网(www.php1.cn)!

Posted in 未分类

发表评论