Python_builder pattern

黄舟
Release: 2016-12-24 15:23:32
Original
1045 people have browsed it

#!/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)!




Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!