Python_ Builder Mode

Source: Internet
Author: User
#!/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 ' fat '
def buildhead (self): PRint u ' build%s header '% Self.type

def buildbody (self):
Print U ' build%s's body '% Self.type

def buildarm (self):
Print U ' build%s's hand '% Self.type

def buildleg (self):
Print U ' build%s's feet '% self.type


#瘦子
Class Personthinbuilder (Personbuilder):
Type = U ' thin '
def buildhead (self):
Print U ' build%s's head '% Self.type

def buildbody (self):
Print U ' build%s's body '% Self.type

def buildarm (self):
Print U ' build%s's hand '% Self.type

def buildleg (self):
Print U ' build%s's feet '% 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 ();

The above is the Python_ Builder model content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.