Cross cutting concerns is set of behaviours needed by the conceptual section s of the program. An example of the cross cutting concerns is Logging.
AOP separates the cross cutting concerns from the functional requirements hence increasing the modularity of the code and making it easier to maintain and decreasing the complexity.
AspectJ is the aspect oriented extension for the Java Programming Language.
Following are the terminologies used in AOP
1. Aspect - General feature we want to apply globally to your application (ex. Logging , transaction Management)
2. Advice - A chunk of code that is invoked during program execution
3. Joinpoint - A single location in the code where an advice should be executed
4. Pointcut - A pointcut is a set of many joinpoints where an advice should be executed
5. Targets/Target Objects - The objects you want to apply an aspect or set of aspects to
6. Introduction - This is the ability to add methods to an object
Different Types of advices in AspectJ are:
1. Before advice: Before advice executes before the execution of the advised join point. The syntax of this advice is before(args) : pointcut_expression {}
2. After advice: After advice executes after the execution of a join point. The syntax of this advice is after(args) returning() : pointcut_expression {}
3. Around advice: Around advice surrounds join points i.e. it can execute before and after the join points execution. The syntax of this advice is around(args) : pointcut_expression {}. Responsibility when using an around advice is calling the join point by using the proceed() method.
4. After Throwing: This advice will be called when an advised join point throws an exception. The syntax of this advice is after(args) throwing() : pointcut_expression {}
Eclipse IDE provides the AspectJ development tools plugin (available in Eclipse MarketPlace) .