What is AOP?
AOP is a continuation of OOP and short for aspect oriented programming, which means Aspect-Oriented Programming. AOP is actually a continuation of the gof design model. The design model tirelessly pursues decoupling between callers and callers. AOP can be said to be an implementation of this goal.
For example, assume that in an application system, a shared data must be accessed concurrently. First, encapsulate the data in a data object called data class, there will be multiple Metadata classes dedicated for accessing the same data object at the same time.
To achieve the preceding concurrent access to the same resource, the lock concept must be introduced. That is to say, when a metadata class accesses this data object at a certain time point, the data object must be locked, unlock unlocked immediately after use, and then provide access to other unlock classes.
Using traditional programming habits, we will create an abstract class. All the class classes inherit this abstract parent class, as shown below:
Abstract class worker { Abstract void locked (); Abstract void accessdataobject (); Abstract void unlocked (); } |
Disadvantages:
Therefore, a newProgramThe structure should focus on the vertical aspect of the system. For example, the "Lock" function of the application. The new program structure is aspect (aspect)
In this application, aspect has the following responsibilities:
Provides essential functions to lock or unlock the accessed objects. To ensure that all the operations on the data object can be called to lock (), after it is used, call unlock () to unlock.
Application Scope of AOP
Obviously, AOP is very suitable for developing J2EE container servers. Currently, JBoss 4.0 is developed using the AOP framework.
The specific functions are as follows:
Authentication permission
Caching Cache
Context passing content transmission
Error Handling
Lazy Loading
Debugging debugging
Logging, tracing, profiling and monitoring record tracking optimization Calibration
Performance Optimization
Persistence persistence
Resource pooling resource pool
Synchronization
Transactions transaction
Is AOP necessary?
Of course, the above application examples have also been solved without using AOP. For example, JBoss 3. xxx also provides the above application functions, but does not use AOP.
However, using AOP allows us to understand software systems from a higher abstract concept. AOP may provide a valuable tool. This can be said: Because the AOP structure is used, the source code of JBoss 4.0 is much easier to understand than JBoss 3.x, which is very important for a large complex system.
From another aspect, it seems that not all people need to care about AOP. It may be an architectural design option. If you choose a J2EE system, the above general aspects of AOP have been implemented by J2EE containers. J2EE application system developers may need to pay more attention to the aspect of industrial applications.
Specific implementation of AOP
AOP is a concept that does not set the implementation of a specific language. It can overcome the disadvantages of a single inheritance feature language (such as Java). Currently, the specific implementation of AOP has the following items:
Aspectj (TM): created in Xerox PARC. has a history of nearly ten years and is mature.
Disadvantages: Too complicated; destroys encapsulation; Special Java compiler is required.
dynamic AOP: Uses JDK's dynamic proxy API or bytecode processing technology.