学习版本3.5.2
外观模式(Facade Pattern)向客户端提供一个可以访问系统的接口,隐藏了系统的复杂性。
比如说,生产a产品需要abc三个流水线生产的零件,我只想管a产品的生产。
class ProductionLineA(object):
def create(self):
print("create component a")
class ProductionLineB(object):
def create(self):
print("create component b")
class ProductionLineC(object):
def create(self):
print("create component c")
class AssembleProductA(object):
def assemble(self):
print("use component a,b and c to assemble product a")
class YieldProduct(object):
def __init__(self):
self.pla = ProductionLineA()
self.plb = ProductionLineB()
self.plc = ProductionLineC()
self.apa = AssembleProductA()
def product(self):
self.pla.create()
self.plb.create()
self.plc.create()
self.apa.assemble()
if __name__ == "__main__":
yp = YieldProduct()
yp.product()
运行结果
create component a
create component b
create component c
use component a,b and c to assemble product a