相关疑难解决方法(0)

如何在Python中编写策略模式与维基百科中的示例不同?

在2009年维基百科的战略模式条目中,有一个用PHP编写的例子.

大多数其他代码示例执行以下操作:

a = Context.new(StrategyA.new)
a.execute #=> Doing the task the normal way

b = Context.new(StrategyB.new)
b.execute #=> Doing the task alternatively

c = Context.new(StrategyC.new)
c.execute #=> Doing the task even more alternative
Run Code Online (Sandbox Code Playgroud)

在Python代码中,使用不同的技术和Submit按钮.我想知道如果Python代码也按照其他代码示例的方式执行它会是什么样子.

更新:使用Python中的第一类函数可以更短吗?

python design-patterns

37
推荐指数
5
解决办法
3万
查看次数

标签 统计

design-patterns ×1

python ×1