切入点和面向方面的编程
如何在面向方面的编程语言中使用切入点向现有程序添加功能?
据我了解,从这篇维基百科文章 - http://en.wikipedia.org/wiki/Pointcut
切入点被放置到一段代码中的特定位置,当到达该点时,根据切入点的评估,可以根据切入点的评估在代码中某处的特定点执行更多代码。这是正确的理解吗?
如果是这样,那么这将增加功能,因为程序员可以根据该评估执行不同的代码段。
How are pointcuts used in aspect-oriented programming language to add functionality into an existing program?
To my understanding, from this Wikipedia article - http://en.wikipedia.org/wiki/Pointcut
Pointcuts are placed into a specific spot in a piece of code, and when that point is reached, based on the evaluation of the pointcut, more code can be executed at a specific point somewhere in the code based on the evaluation of the pointcut. Is this a correct understanding?
If so, then that would add functionality because the programmer can execute different piece of code based off that evaluation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如,我有一个包含许多服务对象的应用程序,我想对每个方法进行计时。使用 AspectJ 表示法:
这里,“execution(public * my.service.package.*(..))”是切入点:它指定将执行通知的连接点集(执行中的所有方法)服务包中的所有类)。
For example, I have an application with a number of service objects and I want to time every method. Using AspectJ notation:
Here, the "execution(public * my.service.package.*(..))" is the pointcut: it specifies the set of join points for which the advice will be executed (the execution of all methods in all classes in the service package).
切入点是连接建议(“纯”代码片段,不关心它将在哪里运行)和连接点(执行点,如方法调用或返回,不关心将运行什么代码)。
我将切入点称为谓词函数,该函数选择将与当前方面一起使用哪些连接点(为每个建议的每个连接点提供 true/false 的谓词)。
Pointcut is what connects advices ("pure" code fragments that don't care where exactly it will be run) and join points (points of execution like method call or return, that don't care what code will be run).
I would call pointcut a predicate function that chooses which join points are going to be used with current aspect (predicate that gives true/false for each join point for each advice).