Definitions
As per the documentation:
Join point: a point during the execution of a program, such as theexecution of a method or the handling of an exception.
You can consider Joint Points as events in execution of a program. If you are using Spring AOP, this even is limited to invocation of methods. AspectJ provides more flexibility.
But you never handle all events as you don't eat all the food in the menu when you go to a restaurant (I don't know you, you might! But, I certainly don't). So you make a selection of events to handle and what to do with them. Here goes Pointcuts. As per the documentation,
Pointcut: a predicate that matches join points.
Then you associate what to do with the Pointcut, there goes Advice. As per the documentation,
Advice is associated with a pointcut expression and runs at any join point matched by the pointcut.
Code
package com.amanu.example;import org.aspectj.lang.annotation.After;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;/** * @author Amanuel Nega on 10/25/16. */class ExampleBussinessClass { public Object doYourBusiness() { return new Object(); }}@Aspectclass SomeAspect { @Pointcut("execution(* com.amanu.example.ExampleBussinessClass.doYourBusiness())") public void somePointCut() { }//Empty body suffices @After("somePointCut()") public void afterSomePointCut() { //Do what you want to do after the joint point is executed } @Before("execution(* *(*))") public void beforeSomePointCut() { //Do what you want to do before the joint point is executed }}
Explanation of Code
ExampleBusinessClass
when proxy-ed, is our target!doYourBusiness()
is a possible joint pointSomeAspect
is our aspect that crosses in to multiple concerns such assExampleBusinessClass
somePointCut()
is a definition of a point cut that matches our joint pointafterSomePointCut()
is an advice that will be executed after oursomePointCut
point cut that matchesdoYourBusiness()
joint pointbeforeSomePointCut()
is also an advice that matches allpublic
method executions. UnlikeafterSomePointCut
, this one uses an inline point cut declaration
You can look at the documentation if you don't believe me. I hope this helps