在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中的第一类函数可以更短吗?