#!/usr/bin/python
# -*- programming:utf-8 -*-
#Builder-Basisklasse
class PersonBuilder():
def BuildHead ( self):
: Baue den Kopf von %s' % self.type
def BuildBody(self):
print u'Build %s' body' % self.type
def BuildArm(self) :
print u' Build %s's hand' % self.type
def BuildLeg(self):
print u'Build %s's foot' % self.type
# Thin
class PersonThinBuilder(PersonBuilder):
type = u'thin'
def BuildHead(self):
print u'Build the head of %s' % self.type
def BuildBody (self):
print u'Build %s' body' % self.type
def BuildArm(self):
print u'Build %s's hand' % self.type
def BuildLeg(self):
print u'Build %s's legs' % self.type
#Director
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();
Das Obige ist der Inhalt des Python_builder-Modus. Weitere verwandte Inhalte finden Sie auf der chinesischen PHP-Website (www.php.cn). )!