<filename>designPattern/creational_patterns_创建型设计模式/builder_pattern_建造者模式/builder_建造者模式.py
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# author: bigfoolliu


"""
python建造者模式实现

- 可以用来创建需由其他复杂对象组合而成的对象
- 区别于抽象工厂模式，可以保存了复杂对象各部分细节
"""

from abc import ABCMeta, abstractmethod


class Builder(object):
    """接口类，定义创建对象的方法"""

    __metaclass__ = ABCMeta

    @abstractmethod
    def draw_left_arm(self):
        pass

    @abstractmethod
    def draw_right_arm(self):
        pass

    @abstractmethod
    def draw_body(self):
        pass


class Thin(Builder):
    """创造者类"""

    def draw_left_arm(self):
        print("瘦子画左手")

    def draw_right_arm(self):
        print("瘦子画右手")

    def draw_body(self):
        print("瘦子画身体")


class Fat(Builder):
    """创造者类"""

    def draw_left_arm(self):
        print("胖子画左手")

    def draw_right_arm(self):
        print("胖子画右手")

    def draw_body(self):
        print("胖子画身体")


class Director(object):
    """
    指挥员类，可以指定由哪个创造者来创造
    接收创造者对象为参数
    """

    def __init__(self, person):
        self.person = person

    def draw(self):
        self.person.draw_left_arm()
        self.person.draw_right_arm()
        self.person.draw_body()


if __name__ == '__main__':
    thin = Thin()
    director_thin = Director(thin)
    director_thin.draw()

    fat = Fat()
    director_fat = Director(fat)
    director_fat.draw()

<filename>designPattern/creational_patterns_创建型设计模式/builder_pattern_建造者模式/builder_建造者模式.py
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# author: bigfoolliu


"""
python建造者模式实现

- 可以用来创建需由其他复杂对象组合而成的对象
- 区别于抽象工厂模式，可以保存了复杂对象各部分细节
"""

from abc import ABCMeta, abstractmethod


class Builder(object):
    """接口类，定义创建对象的方法"""

    __metaclass__ = ABCMeta

    @abstractmethod
    def draw_left_arm(self):
        pass

    @abstractmethod
    def draw_right_arm(self):
        pass

    @abstractmethod
    def draw_body(self):
        pass


class Thin(Builder):
    """创造者类"""

    def draw_left_arm(self):
        print("瘦子画左手")

    def draw_right_arm(self):
        print("瘦子画右手")

    def draw_body(self):
        print("瘦子画身体")


class Fat(Builder):
    """创造者类"""

    def draw_left_arm(self):
        print("胖子画左手")

    def draw_right_arm(self):
        print("胖子画右手")

    def draw_body(self):
        print("胖子画身体")


class Director(object):
    """
    指挥员类，可以指定由哪个创造者来创造
    接收创造者对象为参数
    """

    def __init__(self, person):
        self.person = person

    def draw(self):
        self.person.draw_left_arm()
        self.person.draw_right_arm()
        self.person.draw_body()


if __name__ == '__main__':
    thin = Thin()
    director_thin = Director(thin)
    director_thin.draw()

    fat = Fat()
    director_fat = Director(fat)
    director_fat.draw()

#!/usr/bin/env python3 # -*- coding:utf-8 -*- # author: bigfoolliu python建造者模式实现  - 可以用来创建需由其他复杂对象组合而成的对象 - 区别于抽象工厂模式，可以保存了复杂对象各部分细节 接口类，定义创建对象的方法 创造者类 创造者类 指挥员类，可以指定由哪个创造者来创造     接收创造者对象为参数