Created by Wang, Jerry on Jul 25, 2016
Joint Point
A join point is an identifiable point in the execution of a program. It could be a call to a method or an assignment to a member of an object.
join point 是程序执行过程中可以被识别的点。它可以是对一个函数的调用或是对象的一个属性。(注:spring的AOP只能做到对函数调用的拦截)
例子:
Public class Account{
void credit(float amount){
_balance += amount;
}
}
这个例子中的join point包括Account类中执行credit()方法和对_balance的操作。
Pointcut
A pointcut is a program construct that selects join points and collects context at those points. For example, a pointcut can select a join point that is a call to a method, and it could also capture the method’s context, such as the target object on which the method was called and the method’s arguments.
We can write a pointcut that will capture the execution of the credit() method in the Account class shown earlier:
execution(void Account.credit(float))
To understand the difference between a join point and pointcut, think of pointcuts as specifying the weaving rules and join points as situations satisfying those rules.
pointcut 是一种程序结构,它用于选取join point并收集这些point的上下文信息。举例来说,pointcut可以是一个调用方法的join point,并且它能捕获这个方法的上下文信息,例如调用这个方法的目标对象和该方法的属性。
我们可以写一个pointcut,它将可以捕获前面Account类中credit()方法的执行:
execution(void Account.credit(float))
要想理解join point和pointcut的不同,可以把pointcut想成明确了织入的规则,而join point则声明了符合这些规则的情况(即什么情况下运用织入的规则)。