1. Preface
Aspect oriented Programming (AOP) is a hot topic recently.
ASPECTJ is the implementation of the AOP Java language, and has received extensive attention from Java programmers.
For specific information about ASPECTJ and AOP, find from the following links:
http://www.eclipse.org/aspectj/
http://www.parc.com/research/csl/projects/aspectj/
http://aosd.net/
There is a lot of information on the web that explains AspectJ, but most of it starts with explaining ASPECTJ syntax, and then explains how to apply aspectj, how to separate different aspects of the software development process (Aspect)--log,session,authentication and Authorization,transaction, wait.
The first contact with ASPECTJ readers to see this information (or grammar manual), will feel aspectj some mysterious. They want to know how aspectj do this? How does the ASPECTJ work? Does ASPECTJ need a special operating environment?
This article from another angle explains AspectJ, this article from explains AspectJ's design idea, the operation principle starts, answers these questions.
This article explains the main content, according to the importance of the concept, arranged as follows:
ASPECTJ is a code generation tool (Generator).
ASPECTJ syntax is the syntax used to define code generation rules. If you've ever used Java Compiler Compiler (JavaCC), you'll find that the code generation rules for both are surprisingly similar.
ASPECTJ has its own grammar compiler tool, the result of the compilation is Java class file, when run, Classpath need to include a aspectj jar file (Runtime Lib).
Comparison of AspectJ and Xdoclet. Comparison of ASPECTJ and EJB descriptor.
The principle of this article is to speak only the things that are not mentioned in other materials, the things that other materials have told, not to speak or to say. To save the network resources, but also to save everyone valuable time.
2. Aspect oriented Programming (AOP)
This section briefly introduces the concept of AOP and explains why we need AOP.
AOP is a complement to object oriented programming (OOP).
OOP can solve the problem of object data and encapsulation well, but it can't solve the problem of aspect ("aspect") separation well. The following examples are specified.
For example, we have a bank class. Bank has two methods, deposit (save) and withdraw (withdraw money).
The classes and methods are defined as follows:
Code 2.1 Bank.java
class Bank{
public float deposit(AccountInfo account, float money){
// 增加account账户的钱数,返回账户里当前的钱数
}
public float withdraw(AccountInfo account, float money){
// 减少account账户的钱数,返回取出的钱数
}
};