调用第一个方法时触发对第二个方法的调用
假设您的 method1 不包含对 method2 的显式调用。
是否有任何编程语言支持在调用 method1 时调用 method2 而不对第一个方法进行任何修改?如果是这样,请举一个简短的例子。
Say you have method1 that contains no explicit calls to method2.
Do any programming languages support a way to call method2 when method1 is called with no modification whatsoever to the first method? If so please give a short example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,AspectJ 就是其中之一。它看起来像这样:
也就是说,在
method1
被调用后,执行给定的代码(它只调用method2
。整个事情是称为通知。call(void method1())
部分称为切入点;切入点是一组连接点< /em>---程序中可以修改行为的指定位置或相关的切入点和建议可以分为方面——因此,还有其他具有类似功能的面向方面的语言。
Yes, AspectJ, for one. It would look something like this:
That is, after
method1
is called, execute the given code (which just callsmethod2
. The whole thing is called advice. Thecall(void method1())
part is called a pointcut; a pointcut is a set of join points---specifiable places in your program where behavior can be modified or new behavior injected. Related pointcuts and advice can be grouped into aspects---thus the name of the language.There are other aspect-oriented languages with similar capabilities.
在“第一类依赖关系的反射模型”中,作者描述了一种语言,在该语言中,可以借助元对象以“与其他应用程序关注点正交”的方式表达此类依赖性。但这只是一个研究原型。对元对象和元对象协议的研究导致了面向方面的编程,它进入了工业界,而且确实可能是更现实的使用方式。
In "A Reflective Model for First Class Dependencies" the author describes a language where such dependencies can be expressed in a manner "that is orthogonal to other application concerns" with the help of meta-objects. But that was a research prototype. Research on meta-objects and meta-object protocols led to aspect-oriented programming, which made its way to industry, and which is indeed probably what would be the more realistic to use.