Some concepts of AOP and LOOM. NET

Source: Internet
Author: User

Aspect-oriented programming (aspect-oriented programming, AOP) is a term in computer science and refers to a programming paradigm. This model is based on a language structure called the side (aspect), and the side is a new modular mechanism, used to describe the cross-concern (crosscutting concern) distributed in objects, classes, or functions ).
The above is the concept of AOP in Wikipedia, which is obscure in abstraction. Here is my understanding. In case of any errors, please note that you are not very grateful.
AOP involves many concepts and is dazzled. However, the idea of AOP is very simple. Is to separate the code. Separates the most common and global methods and inserts them horizontally into the main system code. The so-called horizontal interspersed Code does not directly call the code in the trunk code, but triggers the code at the defined connection point through some mechanisms (such as reflection. The connection point defines when the code is triggered.
AOP is usually used to capture exceptions, track exceptions, and inject Security checksum failures. In OO programming, classes and methods are designed to execute special operations, and some common methods are scattered into public classes. However, there are many (cross-cutting concerns) cross-cutting concerns that traverse all classes and methods, such as logging and permission detection. In OOP, users define different log classes and permission detection, and call these log classes and permission classes in the classes or methods that require logging or permission verification, some solve these problems. Using AOP can solve these problems elegantly.
In AOP, the so-called "aspect" is simply to encapsulate the logic or responsibilities that are irrelevant to the business but are called by the business module to reduce repeated system code, reduce the coupling between modules and facilitate future operability and maintainability. In general, it is to encapsulate those functions used for horizontal insertion and call these functions at specific times. Therefore, it can be understood as the encapsulated library of the function used for horizontal insertion. These methods are woven at the connection point with the target method. The so-called weaving is to call the target method and will certainly trigger the horizontal insertion method.
There are two ways to weave in AOP. Dynamic and Static.
Static AOP systems such as AspectJ are woven during compilation or loading. The aspect after weaving cannot be deleted or configured at runtime. Static knitting is usually implemented through MSIL or bytecode rewriting.
The dynamic AOP system can be used for runtime knitting. The programmer dynamically configures the program running.
Typical Implementation of the AOP system, whether static or dynamic, usually inserts a hook at the execution point ).
This execution point is the so-called connection point. The program runs to the connection point. The Hook intercepts the program and calls a piece of code called advice. Different notifications can be associated with different entry points. One aspect is a pair of entry points and notifications.
In static-woven AOP, hooks are usually embedded in code and embedded through static source code or bytecode translation.
For AOP with weaving, you must check whether a notification (advice) is required at each connection point ). In dynamic AOP, the connection points all depend on the execution context, because the connection points are specified at runtime and sometimes change dynamically. Therefore, after the connection point is changed, you must re-check whether a notification is required.
Currently, the mature AOP language is called AspectJ, which is used in Java .. NET, such as AspectDNG, Aspect #, PostSharp, and LOOM. NET.
LOOM. NET is an open source AOP system that supports both dynamic and static weaving.
If dynamic knitting is performed, the RapierLoom. dll assembly is introduced, and the knitting process is initialized by a factory class at runtime. The Create or CreateInstance method is used to generate the braided object during initialization.
Static knitting occurs after compilation. Rewrites some additional glue code in the generated Assembly through the Gripper-LOOM.NET ". The Knitting procedure is as follows: first generate the. NET program set, and then run the command line gl.exe on the program set.

Related Article

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.