编程语言
首页 > 编程语言> > (Python3 代码实现)《大话设计模式》九:建造者模式

(Python3 代码实现)《大话设计模式》九:建造者模式

作者:互联网

在这里插入图片描述

class Person:
    def create_head(self):
        pass

    def create_hand(self):
        pass

    def create_body(self):
        pass

    def create_foot(self):
        pass


class ThinPerson(Person):
    def create_head(self):
        print("thin head")

    def create_hand(self):
        print("thin hand")

    def create_body(self):
        print("thin body")

    def create_foot(self):
        print("thin foot")


class ThickPerson(Person):
    def create_head(self):
        print("thin head")

    def create_hand(self):
        print("thin hand")

    def create_body(self):
        print("thin body")

    def create_foot(self):
        print("thin foot")


class Director:
    def __init__(self, temp):
        self.p = temp

    def create(self):
        self.p.create_head()
        self.p.create_hand()
        self.p.create_body()
        self.p.create_foot()


if __name__ == "__main__":
    p = ThickPerson()
    d = Director(p)
    d.create()

标签:__,大话,self,Python3,print,设计模式,create,def,thin
来源: https://blog.csdn.net/weixin_39020133/article/details/113198219