Python设计模式之“抽象工厂模式”
newbie_evolve
posted @ 2013年8月16日 14:02
in python之年
, 2815 阅读
抽象工厂模式:所谓的抽象工厂是指一个工厂等级结构可以创建出分属于不同产品等级结构的一个产品族中的所有对象。
抽象工厂角色、具体工厂角色、抽象产品角色、具体产品角色
http://blog.csdn.net/ipqxiang/article/details/1955677
class ProductA():
def Show(self):
pass
class ProductA1(ProductA):
def Show(self):
print "this is ProductA 1"
class ProductA2(ProductA):
def Show(self):
print "this is ProductA 2"
class ProductB():
def Show(self):
pass
class ProductB1(ProductB):
def Show(self):
print "this is ProductB 1"
class ProductB2(ProductB):
def Show(self):
print "this is ProductB 2"
class Factory():
def CreateProductA(self):
pass
def CreateProductB(self):
pass
class ConcreateFactory1(Factory):
def CreateProductA(self):
productA = ProductA1()
return productA
def CreateProductB(self):
productB = ProductB1()
return productB
class ConcreateFactory2(Factory):
def CreateProductA(self):
productA = ProductA2()
return productA
def CreateProductB(self):
productB = ProductB2()
return productB
if __name__ == "__main__":
pd = ConcreateFactory1()
p = pd.CreateProductA()
p.Show()
2022年1月25日 17:12
Provide a throwaway mask not to mention glove, some disinfectant, a sprayer and then a cloth for the purpose of cleaning. Word: dispose from mask not to mention glove right after you are actually done using them to stay away from further get spread around of bacterial infection. Dust furniture most certainly table not to mention desk, thereafter usage soapy water unpick particles that bring about infections. In such a manner you reduce the likeliness from germs, virus not to mention bacteria persisting when the disinfection system.