What is AOP?

xiaoxiao2021-03-06  51

What is AOP?

Mountain bridge http://www.jdon.com 2004/01/09

Why is the J2EE container and J2EE application?

We know that J2EE application is only available in the J2EE container to run, then why is it divided into J2EE container and J2EE application? Through the analysis of J2EE container operation mechanisms (see my electronic textbook "EJB practical principle"), we can find that the J2EE container has separated some general features of the general application system, such as transaction mechanism, security mechanism, and object pool or thread. Pool and other performance optimization mechanisms.

These functional mechanisms are almost required for each application, so they can be separated from the specific application system to form a universal framework platform, and the design development of these functional mechanisms has a certain difficulty, while operating stability and rapidity. It is very important to accumulate long debugging and running experience, thereby forming a special J2EE container server product such as Tomcat JBoss, WebSphere, WebLogic, etc.

From the J2EE system, it is divided into two aspects of J2EE containers and J2EE applications, and we have seen a Separation Of Concerns.

Disperse

Separate general demand functions from irrelevant classes; at the same time, many classes can share a behavior, once the behavior changes, there is no need to modify many classes, as long as this behavior can be modified.

AOP is this programming method that realizes dispersion, it will "pay attention" into "aspect".

What is AOP?

AOP is OOP continuation, which is an abbreviation of Aspect oriented Programming, meaning aspect programming.

Example: Suppose there is a shared data must be simultaneously accessed by concurrent data, first, in the data object, called Data Class, and there will be multiple access classes, specifically used for Access this same data object at the same time.

In order to complete the function of the above-mentioned concurrent access to the same resource, it is necessary to introduce the concept of lock Lock, that is, at a moment, when there is an access class to access this data object, this data object must be locked locked Locked, immediately unlocked UNLOCKED, re-access.

Using traditional program habits, we will create an abstract class, all access classes inherit this abstract parent class, as follows:

Abstract class worker {

Abstract void Locked ();

Abstract void accessDataObject ();

Abstract void unlocked ();

}

Disadvantages:

The AccessDataObject () method requires related code such as "lock" status. Java only provides a single inheritance, so the specific access class can only inherit this parent class. If the specific access class also inherits other parent classes, such as another parent class such as Worker, will not be able to implement. Reuse is discounted, the specific access class is only reused in the relevant "lock", which can only be reused in the case where the "lock" is also reused. Carefully study the "lock" of this application, in fact, the following characteristics: "Lock" function is not the primary or primary function of the specific access class, and the main function of the access class is to access the data object, such as reading data or change action. "Lock" behavior is actually independent and distinguishing between the main functions of the specific access class. The "lock" function is actually a longitudinal section of this system involving many classes, many ways. As shown below:

Therefore, a new program structure should be the longitudinal section of the system, such as the "lock" function of this application, this new program structure is aspect (aspect) in this application, "lock" (aspect) should have the following duties :

Provide some essential features to lock or unlock the visited objects. To ensure that all Lock () locks can be called before the operation of modifying the data object, the unlock () unlocked after it is used.

AOP application range

It is clear,

AOP is ideal for developing J2EE container servers, current JBoss 4.0 is using

AOP framework development.

The specific functions are as follows:

Authentication permissions

Caching cache

Context passing content

Error Handling error handling

Lazy loading lazy loading

Debugging debugging

Logging, Tracing, Profiling and Monitoring record tracking optimization calibration

Performance Optimization Performance Optimization

Persistence persistence

Resource pooling resource pool

Synchronization synchronization

Transactions transaction

Is AOP necessary?

Of course, the above application example is not used

In the case of AOP, it has also been resolved, for example, JBoss 3.xxx also provides the above application function, but no use

AOP.

But use

AOP allows us to understand the software system from a higher abstract concept.

AOP may provide a valuable tool. Can say this:

AOP structure, now JBoss 4.0 source code is much easier to understand than JBoss 3.x, which is very important for a large complex system.

From another aspect, it seems that all people need to care.

AOP, it may be a selection of architecture design, if you choose J2EE system,

The above general aspects of AOP have been implemented by J2EE containers, and J2EE application system developers may need to pay more attention to industry applications aspect.

AOP specific implementation

AOP is a concept that does not set the implementation of the specific language, which can overcome the shortcomings of only single inheritance characteristics (such as Java), currently

AOP specific implementation has the following items:

AspectJ (TM): Created in Xerox Parc. There are nearly ten years of history, mature

Disadvantages: too complicated; destroying packages; need special Java compiler.

dynamic

AOP: Using JDK dynamic proxy API or byte size bytecode processing technology.

The specific items based on the dynamic agent API are:

JBoss 4.0 JBoss 4.0 Server

Nanning This is a project named in Nanning, China, is not clear why China is related? Is the Chinese initiated?

Bytecode-based projects are:

Aspectwerkz

Springframework

In other articles, I will continue to

The AOP concept is analyzed and makes progress together with you.

转载请注明原文地址:https://www.9cbs.com/read-115016.html

New Post(0)