首页 > 其他 > 详细

设计模式学习 7 月6 号

时间:2015-07-06 11:40:00      阅读:151      评论:0      收藏:0      [点我收藏+]

一 : 简单工厂模式

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++:

 

设计模式学习 7 月6 号

原文:http://www.cnblogs.com/xxlCMD/p/4623709.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!