python命令模式

2019-01-08 14:37 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011747152/article/details/85846942

#命令模式
class Command():
    def order(self):
        pass
class ACommand(Command):
    def __init__(self,receive):
        self.__receive=receive
    def order(self):
        print("A Command")
        self.__receive.doSomething()
class BCommand(Command):
    def __init__(self,receive):
        self.__receive=receive
    def order(self):
        print("B Command")
        self.__receive.doSomething()
class AReceive():
    def doSomething(self):
        print("A receive")
class BReceive():
    def doSomething(self):
        print("B receive")
class Invoker():
    def __init__(self,command):
        self.__command=command
    def action(self):
        self.__command.order()
t=Invoker(BCommand(AReceive()))
t.action()

在这里插入图片描述

发表评论

您必须 登录 才能发表留言!