I. Basic CONCEPTS
ASPECTJ is a Java based implementation for cutting-plane programming. It adds a new concept of join point to Java, but it's just the name of a Java concept that exists. It adds a little new structure to the Java language: pointcuts (pointcut), Notifications (Advice), type declarations (Inter-type declaration), and Aspects (Aspect). Pointcuts and notifications dynamically affect program processes, and the declarations between types are static class-level structures that affect the program, while the slice is the encapsulation of all these new structures.
The concepts based on cutting, connection points, pointcuts, and notifications are as follows:
The Aspect:aspect declaration is similar to a class declaration in Java and contains some Pointcut and corresponding Advice in Aspect.
Joint point: Represents points that are explicitly defined in a program, typically including method calls, access to class members, and execution of exception handler blocks, which itself can also nest other joint.
Pointcut: Represents a set of joint point, which are either grouped together by logical relationships or assembled by means of a wildcard, regular expression, and define where the corresponding Advice will occur.
Advice:advice defines the action to be done within the pointcut defined in the before, which distinguishes between each joint point before, after, or in lieu of executing code.
The connection point is the appropriate point in the program flow. Pointcuts collect specific set of connection points and the values in those points. A notification is the code that executes when a connection point arrives, and these are the dynamic parts of the ASPECTJ. In fact, the connection point is like a piece of the program in a statement, and the pointcut is a specific statement set at a breakpoint, it collects information at the end of the stack, and notice is the breakpoint before and after the want to join the program generation. There are also a number of different types of declarations in AspectJ that allow programmers to modify the static structure of the program, the name, the members of the class, and the relationships between classes. The aspect in AspectJ is a modular unit of crosscutting concerns. They behave like classes in the Java language, but they also encapsulate pointcuts, notifications, and type declarations
Ii. How to develop an AOP program based on AJDT:ASPECTJ Development tools?
Follow the instructions on the AJDT Web site to install the AJDT plugin in Eclipse http://www.eclipse.org/ajdt/
Creating ASPECTJ Project Projects
For code Development (this article provides a simple example)
Three, simple example:
Copy Code code as follows:
Package aop.test;
Public interface Figureelement {
public void SetXY (int x,int y);
public void Draw ();
}
Copy Code code as follows:
Package aop.test;
Public class Point implements Figureelement {
public int x;
private int y;
public int GetX () {
return x;
}
Public String SetX (int x) {
System.out.println ("Set x Value: x=" +x);
this.x = x;
Return "value is x=" +X;
}
public int GetY () {
return y;
}
public void sety (int y) {
This.y = y;
}
Public Point () {
}
Public point (int x,int y) {
This.x=x;
This.y=y;
}
@Override
public void SetXY (int x,int y) {
This.x=x;
This.y=y;
System.out.println ("Point setxy:x=" +x+ ", y=" +y);
}
@Override
public void Draw () {
System.out.println ("point Draw");
}
@Override
Public String toString () {
Return "point:x=" +x+ ", y=" +y;
}
}