This article provides an introduction to Aspect oriented programming(AOP) and also explains the commonly used terms and concepts used for implementing AOP.
Aspect Oriented Programming(AOP)
Aspect Oriented Programming deals with cross-cutting systems in a system.
Some examples of cross-cutting concerns could be logging, security, transaction management, security etc.
AOP is built on Object oriented programming(OOP). It handles separation of concerns better.
Here are some terminologies used in AOP :
An advice is the service that an aspect will be providing.
It defines what an aspect will do and when it will be doing it,like before a method of after a method, etc.
Spring aspects can work with 5 types of Advice :
1) Before : Advice runs before a method execution
2) After : Advice runs after a method execution
3) After-returning : Advice runs after method successfullly completes
4) After-throwing : Advice runs after method throws an exception
5) Around : Advice runs before and after method execution
A joinpoint is a point in application code, where aspect can be plugged in.
This could a point when a method is called, or a field is modified or an exception is thrown etc.
For example, if you want to introduce a piece of code when an instance of a class is created, then the constructor invocation becomes the join point.
It is difficult to apply aspect code at each and every Joinpoint.
An introduction allows you to add new methods or variables in existing classes without modifying them.
An aspect is a module of cross-cutting concern.
It is a collection of advice, pointcuts and introductions.
This is the process of applying aspects to target object to create proxy object.
Weaving can happen at compile time, class load time or at Runtime.
Weaving in Spring AOP happens at Runtime.
© 2016, www.topjavatutorial.com. All rights reserved. On republishing this post, you must provide link to original post