【问题标题】:Python Strategy Pattern: using class wrapper not function + simple_vs_easy_logicPython 策略模式:使用类包装器而不是函数 + simple_vs_easy_logic
【发布时间】:2013-06-25 21:32:34
【问题描述】:

我正在尝试使用 S.Lott 的 response 构建一个策略模式。
问题是函数返回 None。
我正在使用 Hickey 的 Simple vs Easy {what、how、who}-逻辑。
-[什么] I/O

class base_fnc(object):
    def fncExc(self,data1,data2):
        return

-[HOW] DATA queue[where,when](直接注入)

class stump( base_fnc ):
    def fncExc(self, d1, aContext):
       return d1

class MAB(base_fnc ):
     def fncExc(self, d, aContext ):
        return d+10

-[WHO] API

class context( object ):
    def __init__(self, alt_how_class ):
        self.how = alt_how_class

    def exc(self, d ):
        return self.how.fncExc(d, self)

if __name__ == "__main__":
    c1 = context(MAB())
    ss=c1.exc(10) 
    print ss

ss 打印无

【问题讨论】:

  • 投反对票,因为这不太可能对其他人有用。无意冒犯。

标签: python strategy-pattern


【解决方案1】:

您不会在exc 中返回。你需要做return self.how.fncExc(d, self)。

【讨论】:

    猜你喜欢
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 2014-09-25
    • 2012-02-17
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    相关资源
    最近更新 更多