Home  >  Article  >  Backend Development  >  Python_builder pattern

Python_builder pattern

黄舟
黄舟Original
2016-12-24 15:23:321101browse

#!/usr/bin/python
# -*- coding:utf-8 -*-

#Builder base class
class PersonBuilder():
def BuildHead(self):
def BuildBody(self ):

PASSf DEF Buildarm (Self):
Pass

DEF Buildleg (Self):
Pass

#Fatty
Class Personfatbuilder (PersonBuilder):
Type = U 'Fat Buildhead (fat man' Self: Print u'Build the head of %s' % self.type

def BuildBody(self):
print u'Build the body of %s' % self.type

def BuildArm(self):
print u'Build the body of %s % self.type

def BuildLeg(self):
% self.type


(self):
          print u 'Build the head of %s' % self.type

    def BuildBody(self):
                  print u 'Build the body of %s'   % self.type

    def BuildArm(self):
                                               u'Build %s's hand' % self.type

def BuildLeg(self):
print u'Build %s's foot' % 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();


The above is the content of Python_builder mode. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn