标签:
一 : 简单工厂模式
Python:
class Operation :
def GetResult(self):
pass
class OpertationAdd(Operation):
def GetResult(self,o1,o2):
return o1+02
class OperationDiv(Operation):
def GetResult(self,o1,o2):
tyr:
return o1/o2
except:
print: "error.divided by zero"
return 0
class OperationUndef(Operation):
def GetResult(self):
print "Undefine operation."
return 0
class OperationFactory:
operations = {}
operations[‘+‘] = OperationAdd()
operations[‘/‘] = Operationdiv()
def createOperation(self,ch):
if ch in self.operation:
op = self.operation[ch]
else:
op = OperationUndef()
return op
C++:
标签:
原文地址:http://www.cnblogs.com/xxlCMD/p/4623709.html