CGLIB, NCGLIB and AOP
Programmers who care about the programming have been familiar with the feelings of AOP. Whether it is based on .NET-based implementation or Java-based implementation, there are many open source projects available. Readers who don't understand AOP can go to the AOP column, familiar with the basic concept of AOP. Recalling AOP's history, AOP is not "new" concept in recent years, and it is said that history can be traced back to a laboratory of Xerox. From the assembly language, the process-oriented programming, in the programming idea that is now widely accepted OOP, people gradually abstract the description of the real world. The progress of this step makes us more easily controlled and implemented on large-scale software programming. So why is AOP now received wide attention in the industry? On the one hand, OOP is relatively mature, and it has gradually revealed that it does not effectively solve, which requires new ideas to fill. On the other hand is the progress of the program language. Everyone knows that one of the features of AOP is Interception, which is intercepted. For example, before execution, in execution, it is performed, and there are some additional methods, typical is log, permissions, and transaction control. It is almost impossible to implement methods for .NET, where virtual machine Java and CLR occurs. Single from Interception, the QQ of the corals and wood version is an implementation with AOP characteristics. Everyone is interested in understanding the implementation of the QQ of the coral or wood version, it can be said that it is painful, experienced countless reconciliation and compilation testing, it has achieved interception of QQ related methods. Because whether Java's bytecode, or .NET's pseudo-compilation, they are not the final machine code, but the platform-independent code, which requires translating into machine code when specific implementation. 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. Generally speaking, there are three ways to implement AOP: 1 Let the code have AOP characteristics before compiling into an intermediate code, such as AspectWikez; 2 use language characteristics, start AOP from design methods, such as Java-based dynamic proxy implementation AOP . (See me Nanning series); 3 When running in the middle code, dynamically modify the intermediate code to have AOP characteristics. The shortcomings of the three methods I think there are a few points: one way to adopt, generally requires the compiler's expansion support, just like the Assessor, it takes 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 in Java can use cglib, javassist, etc. in the world of .NET, NCGLIB. Let us give some code examples below. (To be continued) Reference article: Also talk about a program is Debug or release a primer for aspect-oriented programming in java reflection Send actual combat (-) invokemember http://aspectsharp.sourceforge.net/
Dynamic class generation through EMIT
Interoperability of .NET WS client and Axis server Nucleus.MockAop.net:OpenSource .NET AOP Framework