Maison >développement back-end >Tutoriel Python >Modèle Python_builder
#!/usr/bin/python
# -*- coding:utf-8 -*-
#Builder classe de base
class PersonBuilder():
def BuildHead ( self):
):
passer
#fat
class PersonfatBuilder (personbuilder):
type = u'fat '
def buildhead (self): imprimez u' Construisez la tête de %s' % self.type
def BuildBody(self):
print u'Build %s' body' % self.type
def BuildArm(self) :
print u'Construisez la main de %s' % self.type
def BuildLeg(self):
print u'Construisez le pied de %s' % 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' hand' % self.type
def BuildLeg(self):
print u'Build %s's legs' % self.type
#Director
class PersonDirector():
pb = Aucun ;
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();
Ce qui précède est le contenu du mode Python_builder Pour plus de contenu connexe, veuillez faire attention au site Web PHP chinois (www.php.cn). )!