python aop
发布于
Top
python aop

动态语言提供了在运行时改变程序结构的能力,有时候会提供巨大的方便

函数调用拦截是aop的基础

class Target:
    def targetFunc(self):
        print ("targetFunction")

temp=Target.targetFunc

def foo(self):
    print ("before call")
    temp(self)
    print ("after call")

Target.targetFunc=foo

t=Target()
t.targetFunc()

对调用者来说根本就不知道函数已经给动了手脚

用Java, C++来实现就麻烦些了