CGLIB, NCGLIB and AOP

xiaoxiao2021-03-06  83

One of the features of AOP is Interception, which is interception. For example, before execution, in execution, it is performed, and there are some additional methods, typical is log, permissions, and transaction control.

Whether it is Java's bytecode, or the pseudo-compilation of .NET, they are not the final machine code, but the platform-independent code, these codes also need to translate into machine code when they are implemented. The emergence of intermediate languages ​​allows us to control more about the code before.

It is because of the possibility of this AOP's theory, it is possible to reflect water to the stream at this time.

There are three ways to implement AOP implementation:

1 Let the code have AOP characteristics, such as aspectWikez before compiling into an intermediate code.

2 Use the language characteristics, start from the design method, implement AOP, such as Java-based dynamic proxy implementation AOP. 3 Dynamically modify the intermediate code when running in the middle code, making it AOP feature.

There is a shortcoming of the three methods above I think there are fews:

One method used, generally requires expansion support of the compiler, as in the case of an argument of the C compiler, requires a long time to verify its stability and efficiency. In addition, for the final developer, it is also necessary to learn these compilers, or the new syntax directives complete these features, of course, the function is also the most powerful.

In the second method, I think it is a light level implementation, such as Nanning and Dynaop, etc., usually such a realization needs to work hard in design. For example, you need to interface-programming. For existing projects, the amount of change is very large.

The third method is between 1 or 2 methods. The AOP is implemented in the third method, and there is no need for each class with an interface, and there is no change in the compiler. His disadvantage is to need superb programming skills. Because of this, there are many items to be packaged with the third method, for the final developers, for example: Spring.

In fact, Spring's AOP is implemented in the first and second methods.

I think the current project species, the large-scale adoption AOP is not suitable. On the one hand, AOP is still developing, and on the other hand, the framework that supports AOP has not been widely accepted.

Because of this, we may wish to manipulate the intermediate code directly, and some AOP features in some critical places of the project.

The world can be used in CGLIB, Javassist, etc. in Java world.

NCGLIB can be used in .NET world

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

New Post(0)