I. Overview of AOP Programming
Object-oriented programming technology into the mainstream of software development has a great impact on the way software development, developers can visualize the system graphically using a set of entities and the relationships between them, allowing them to design larger, more complex systems with shorter development cycles than before. The only problem with OO development is that it is inherently static and that subtle changes in requirements can have a significant impact on development progress.
Aspect-oriented Programming (AOP) complements and Perfects OO technology, allowing developers to dynamically modify the static OO model and construct a system that grows to meet new requirements, just as objects in the real world change themselves in their lifecycle Applications can also have new features in the development process.
For example, many people presumably have had the experience of using a servlet as an entry point in developing a simple Web application, which is to receive input from an HTML form with a servlet, which is returned to the user after being processed. The servlet at the beginning may be very simple, with only the smallest amount of code that meets the needs of the user. However, with the implementation of the second requirement, such as exception handling, security, logging, and so on, the volume of the code increases to the original 三、四倍-called "second demand" because the basic function of the servlet is to accept and process the user's request, and for this purpose, the log, Mechanisms such as security are not essential.
AOP allows you to dynamically change OO static models without having to modify the original static model or add the code needed to meet the second requirement (actually, even the original source code is not needed). What's even more amazing is that the code that is added later can often be concentrated in one place instead of spreading the code that was later added to the entire model as if using OO alone.
Second, the basic terminology
Before introducing the AOP development instance, let's look at several standard AOP terms to better grasp the relevant concepts.
█cross-cutting concern
In the OO model, although most classes have only a single, specific function, they usually share a second requirement with other classes. For example, when a thread enters or leaves a method, we may have to record the log in the class of the data access layer and the class in the UI layer. Although the basic functionality of each class is extremely different, the code used to satisfy the second requirement is essentially the same.
█advice
It refers to additional code that you want to apply to an existing model. In this case, it refers to the log code to run when a thread enters or exits a method.
█point-cut
This term refers to an execution point in an application that requires the preceding cross-cutting concern to be used at this execution point. In this case, a point-cut occurs when a thread enters a method, and another point-cut occurs when the thread leaves the method.
█aspect
The combination of point-cut and advice is called aspect. In the following example, we add a log (logging) aspect by defining a point-cut and giving the appropriate advice.
AOP also has many other features and terminology, such as introduction (Introduction), which introduces interfaces/methods/domains to existing classes-which greatly broadens the imagination of developers. However, this article only introduces some of the most basic features, familiar with the concepts introduced here, you go into the other characteristics of AOP, and see how to use them in your development environment.