欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實現(xiàn)的建造者模式示例

 更新時間:2018年08月06日 11:59:20   作者:初行  
這篇文章主要介紹了Python實現(xiàn)的建造者模式,結合完整實例形式分析了構造者模式的具體定義與相關使用操作技巧,需要的朋友可以參考下

本文實例講述了Python實現(xiàn)的建造者模式。分享給大家供大家參考,具體如下:

#!/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相關內(nèi)容可查看本站專題:《Python數(shù)據(jù)結構與算法教程》、《Python Socket編程技巧總結》、《Python函數(shù)使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經(jīng)典教程

希望本文所述對大家Python程序設計有所幫助。

相關文章

最新評論