Python 抽象工厂

# -*- coding: utf-8 -*-
"""
Created on Sat Mar  3 21:56:58 2018

@author: mz
"""

class IFactory(object):
    def ProduceB(self):
        pass
    
    def ProduceA(self):
        pass
    
    
class IMethod(object):
    def DoAsIMean(self):
        pass

class IOtherMethod(object):
    def DoAsIMean(self):
        pass

class AOtherMethod(IOtherMethod):
    def DoAsIMean(self):
        print("do as a other method means")

class BOtherMethod(IOtherMethod):
    def DoAsIMean(self):
        print("do as b other method means")

class AMethod(IMethod):
    def DoAsIMean(self):
        print("do as a method means")

class BMethod(IMethod):
    def DoAsIMean(self):
        print("do as b method means")
        

class AFactory(IFactory):
    def ProduceA(self):
        print("A factory product->")
        a = AMethod()
        a.DoAsIMean()
        
    def ProduceB(self):
        print("B factory product->")
        b = BMethod()
        b.DoAsIMean()
        
class BFactory(IFactory):
    def ProduceA(self):
        print("A factory product->")
        a = AOtherMethod()
        a.DoAsIMean()
        
    def ProduceB(self):
        print("B factory product->")
        b = BOtherMethod()
        b.DoAsIMean()
    
if "__main__" == __name__:
    a = AFactory()
    a.ProduceA()
    
    b = BFactory()
    b.ProduceA()

运行结果:

A factory product->
do as a method means
A factory product->
do as a other method means

猜你喜欢

转载自blog.csdn.net/mz5111089/article/details/79597221