【发布时间】:2010-12-02 10:34:22
【问题描述】:
我正在寻找 Python 中的 Command 模式实现... (根据Wikipedia,
命令模式是一种设计 对象用于的模式 代表和封装所有 调用方法所需的信息 稍后。
)
我发现的唯一东西是命令调度pattern:
class Dispatcher:
def do_get(self): ...
def do_put(self): ...
def error(self): ...
def dispatch(self, command):
mname = 'do_' + command
if hasattr(self, mname):
method = getattr(self, mname)
method()
else:
self.error()
可能是我错了,但看起来这是两个不同的概念,意外地有相似的名称。
我错过了什么吗?
【问题讨论】:
标签: python design-patterns oop