Spring's AOP terminology

Source: Internet
Author: User

AOP is the abbreviation for Aspect oriented programing. is translated as "aspect-oriented programming".

AOP's approach provides a solution to this repetitive code that cannot be abstracted through a vertical inheritance system through a horizontal extraction mechanism. How to integrate these independent logic into the business logic to complete the same business operations. This is the key to AOP.

1, Connection point (Joinpoint)


A specific location where the program runs: Before the class starts initializing. After the class is initialized. Class before a method call. A class or a piece of code has some specific points of a boundary nature, which are called "Connection points" by specific points in the code.

Spring only supports connection points for methods. Can be used only before a method call. After the method call, the method throws an exception when these program run points are woven into the enhancement.

We know that the hacker attack system needs to find a breakthrough, otherwise it will not be able to attack, to some extent, AOP is a hacker. The connection point is the breach of the attack . Is the candidate for AOP to enter the wedge into the target class.

The connection point is determined by two information: the first is the program running point represented by the method, and the second is the azimuth represented by the relative point.

such as the connection point before the Test.foo () method is run, the run point is Test.foo () and the orientation is the position before the method is run. Spring uses pointcuts to position the run point, while the bearing is defined in the enhanced type.

2. Tangent point (Pointcut)


Each program class has multiple nexus points, such as a class with two methods, both of which are connection points. The connection point is an objective transaction in the program.

But in this large number of connection points, how to locate a connection point of interest? AOP locates specific connection points through the tangent point . The concept of database queries to understand the relationship between pointcuts and connection points is just as good: connection points are equivalent to records in a database. The tangent point is equivalent to the query condition. Pointcuts and connection points are not a one-to-many relationship, and a pointcut can match multiple connection points.

In spring, the tangent point is described by the Org.springframework.aop.Pointcut interface, which uses classes and methods as the query criteria for the connection points, and the spring AOP rules parsing engine is responsible for parsing the query conditions set by the pointcut. Locate the appropriate connection point . In fact, it should be a point of operation rather than a connection point, since the connection point is a detailed program run point that includes azimuth information before the method runs, and the tangency is only positioned on a method, so assume that you want to navigate to a connection point. There is also a need to provide orientation information.

3. Enhancement (Advice)


Enhancement is a piece of program code that is woven into the target class connection point .

Do you think AOP is becoming more and more like hackers? Enhancement is not the King business class in the Trojan loaded?!

In spring. In addition to describing a program code, there is also a connection point related information, which is the location of the point of operation. Together with the run-point orientation and pointcut information, we are able to find a specific connection point. Because the enhancement includes a section of the running logic for joining the target link , and the azimuth information used to Locate the connection point , Spring provides the enhanced interface with the bearing name: Beforeadvice, etc. So there is only a combination of tangent points and enhancements both to determine a specific connection point and implement the pre-increment logic.

4 Object (target)


Enhanced logical weaving of target classes . Assuming there is no AOP, the target business class needs to implement all of its own logic, as Forumservice sees. With the help of AOP, Forumservice only implements the procedural logic of non-crosscutting logic. These crosscutting logic, such as performance monitoring and transaction management, can be dynamically woven into specific connection points using AOP.

5. Introduction (Introduction)


Introduction is a special kind of enhancement . It adds some properties and methods to the class.

Such Even if a business class originally did not implement an interface, through the introduction of AOP, we can dynamically add the implementation of the interface to the transaction logic, so that the business class becomes the implementation of this interface class.

6. Weave in (Weaving)


Weaving is the process of adding enhancements to a detailed connection point to the target class, and AOP, like a loom, weaves together a loom that enhances or introduces the target class to an AOP.

Depending on the implementation technology, AOP has three ways of weaving:,

      1. Compiler weaving: Requires the use of a special Java compiler;
      2. Class loader weaving: Requires the use of special class loaders;
      3. Dynamic agent Weaving: the way to add enhanced generation subclasses to the target class during execution.

Spring is woven with dynamic agents, and ASPECTJ is woven into and out of class loaders with compilers.

7, Agent (proxy)


Once a class is woven into an AOP, it is enhanced. Produces a result class, which is a proxy class that incorporates the original class and the pre-increment logic . Depending on the proxy method. The proxy class may be a class with the same interface as the original class, or it may be a subclass of the original class. So we can invoke the proxy class in the same way we call the original class.

8. Slice (Aspect)


Facets consist of tangency and enhancement (introduction), which contains both the definition of the crosscutting logic and the definition of the connection point, and Spring AOP is the framework responsible for the implementation of the facets, which weaves the crosscutting logic defined by the facets into the link points specified by the facets.

The focus of AOP is on how to apply the enhancement to the target object's connection point, which first consists of two jobs: first: How to locate the connection point by tangency and enhancement, and second: How to write the section code in the enhancement.

Spring's AOP terminology

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.