In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to analyze the principle of AOP programming, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
AOP is a programming idea and a set of specifications.
Software development has experienced the era of process-oriented programming, represented by C language, followed by the era of object-oriented programming, represented by Java language.
In the 21st century, Daniel put forward a new programming idea of aspect-oriented programming, that is, the concept of AOP, full name Aspect-Oriented Programming.
History of development
In 1997, Gregor Kiczales and others first put forward the concept of AOP at the object-oriented programming conference, and then the major companies joined the research. In 2001, the Palo Alto Research Center released AspectJ, the first language that supports AOP, which is also a specification.
Target location
In the process of abstract object-oriented programming in the real world, the code that is always accompanied by a write operation can not achieve modular encapsulation and will be scattered in various objects, especially non-functional code. It is easy to deal with the general functional development by using object-oriented abstraction, but aspect-oriented (aspect-oriented) gives a new way of thinking to consider programming, which can better think about global structure.
So AOP mainly solves two problems:
Code fragmentation issues, especially those that are non-functional.
As a supplement and perfection of object-oriented programming thinking.
Core knowledge points
Connection point
Join point: join point, a point of execution of a program, such as a method in a class, a block of code in a method.
Entry point
Pointcut: point cut is a code structure that captures a join point, which defines a code logic that captures a join point.
Aspect
Aspect; aspect, which is faceted logic code that is executed concretely, similar to a class.
Notice
Notification: advice, which is the code executed by point cut, defines when to execute aspect at the connection point.
Main application scenarios
Scenarios are divided into two categories:
One kind of non-functional requirements, such as logging, exceptions, security, and transactions, can be programmed with AOP ideas.
The other is functional requirements, which adds AOP thinking to the abstract thinking of the original object, which is a kind of structured thinking, which takes into account the commonness of multiple classes when defining classes.
Mainstream AOP language implementation
Besides AspectJ, other AOP implementations are known such as JBoss AOP, Spring AOP, and so on.
Only AspectJ and SpringAOP are introduced here, and the point is that they are different.
AspcetJ
AspectJ uses static weaving method to weave the original code, and provides an independent compiler to weave the java file of the aspect and the original code into a new class file. Provides a detailed compilation log and debugging tools, long compilation time but high efficiency.
Range of support for connection points:
Method and constructor call
Method and constructor execution
Attribute access
Exception handling
Class initialization, which is a block of static code
Grammatical structure
Control flow
Object and parameter type
Conditional test
Notification method of associated connection points:
Before, run before the connection point is executed
After, run after the connection point is executed
Around, the entire outside of the connection point, the whole envelope, the ability to execute and modify the context of the connection point
Spring AOP
Spring AOP does not fully implement the AspectJ language, it is more to expand the Aop capabilities of Spring framwork, make up for the shortcomings of Spring framework and integrate Aop and Spring framwork.
Join points only support method interception calls.
The join point notification method increases the interception of exception triggers by throw on the basis of before, after and around of aspect.
The integration of Spring AOP and Spring IoC systems, the unified management of aspect classes by Spring beans, and provides ProxyFactoryBean's AOP agent factory class, as well as powerful tools for automatic proxy BeanNameAutoProxyCreator and DefaultAdvisorAutoProxyCreator.
Spring AOP is a dynamic weaving that completes the weaving of AOP's aspect code into the original code logic at runtime. The underlying layer uses the dynamic proxy of JDK to implement the AOP proxy, and when the object does not implement the interface, CGLIB will use it by default.
Advantages and disadvantages
Advantages: solve the problem of code clutter, code logic decoupling, easy to maintain, provide scalability and reusability.
Disadvantages: the more aspects, the more complex the system, and the higher the cost for engineers to learn (the business is no longer linear, but becomes leapfrog)
This is the answer to the question about how to parse the principles of AOP programming. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.