建造者模式

用途可以想象成每个ConcreteBuilder都是一栋楼,有几个Concretebuilder就是几栋楼

 

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



class Builder(object):
    """抽象接口类  """

    def BuildPart(self):
        pass

    def GetResult(self):
        pass


class ConcreteBuilder(Builder):
    def BuildPart(self):
        print("a1")

    def GetResult(self):
        print("a2")


class ConcreteBuilder2(object):
    """docstring for """

    def BuildPart(self):
        print("b1")

    def GetResult(self):
        print("b2")


class Director(object):
    """ 指挥者"""

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

    def Construct(self):
        self.arg.BuildPart()
        self.arg.GetResult()

if __name__ == '__main__':
    obj = ConcreteBuilder2()
    ret = Director(obj)
    ret.Construct()

 

posted @ 2016-11-03 19:03  我当道士那儿些年  阅读(133)  评论(0编辑  收藏  举报