< Prev
Next >



AspectJ Programming



In this tutorial, we are going to introduce you to AspectJ programming. Using Aspect Oriented Programming(AOP), we can introduce new features in an existing application without changing its design. Spring Framework provides support for working with Aspect Oriented Programming(AOP)in an enterprise application.

To understand more about AspectJ programming, we must understand the concept of elements in aspect oriented programming. The elements in aspect oriented programming are as follows -





Joinpoint


An application code may have many several points in it at which an important module can be introduced. These points could be a constructor, method, field or a class. These points are known as a joinpoint, where an important module could be introduced. To understand the concept of joinpoint, let's take an example -

Imagine you have an application in which you want to introduce a piece of code that checks the amount of free memory before a new object is created. As the creation of a new object is triggered by the constructor of the class. Hence, the point at which this memory check module could be inserted is the constructor of the class, which becomes the joinpoint.




Pointcut


Once you have located the joinpoint in your application code where an important module could be executed, the next step is to introduce this module in the application on the fulfilment of a particular condition or a situation. This condition is specified using an expression known as pointcut.

For example - A class may have several methods defined in it but if we want to introduce a piece of code only before the execution of methods that takes a String object then we could express this situation using a pointcut expression.




Advice


Advice us to specify the piece of code or a module which needs to be introduced or executed whenever a joinpoint is called by the system. Not just this, but using advice we can even specify a specific time frame at which this module will be introduced in the system, by using various kinds of advice such as -

Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2