What is ASPECTJ

Source: Internet
Author: User

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账户的钱数,返回取出的钱数
}
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.