The Last post is simple and easy. Spring (ii) in the IOC detail, I gave you a brief introduction to the IOC in the core of the spring framework, and then we go on to another core AOP (Aspect oriented programming), the aspect-oriented programming.
1. OOP Review
Before introducing AOP, let's review the familiar OOP (Object oriented programming). OOP is mainly designed to achieve reusability, flexibility and scalability of programming. Some of its features are inheritance, encapsulation, polymorphism and abstraction. OOP focuses on the programming architecture, emphasizing the hierarchical relationships between classes.
2. Oop defects
To better illustrate the concept of OOP, let's follow an example of OOP, focusing on what bugs exist in oop to better understand the relevant aspects of AOP.
First look at the following picture:
The above picture has three classes: Dog,cat and duck, and they all have a way to run. According to Oop's design philosophy, it's easy to think of abstracting a animal parent class, while allowing these three subclasses to inherit the animal parent class. Such a design can be represented in the following illustration:
In OOP, we use a large number of programming methods like the above graph to abstract, inherit, encapsulate and polymorphism the class to achieve reusability, flexibility and extensibility of programming. However, such programming still has some limitations, sometimes, OOP is not very good for us to solve the problems encountered in the actual development. To illustrate this issue, look at the following illustration:
Seeing the above picture, we can not find any problem at the moment. For everyone to understand, next I will explain to you the above class diagram implementation process. Described below: The circus has a performance puppy, the puppy can run and jump, but before it finishes running and jumping two moves, it must be after receiving an order from the trainer, and after running and jumping, the trainer will reward the response, such as a piece of meat.
After understanding the implementation process, we are looking at the specific code.
public class Dog {public
void run () {
System.out.println) ("The trainer gives the order!")
System.out.println ("The puppy begins to run!") ");
System.out.pringln ("Trainer gives reward");
public void Jump () {
System.out.println ("the trainer gives the order!")
System.out.println ("The puppy begins to jump!") ");
System.out.pringln ("Trainer gives reward");
}
Looking at the code above, we can see that in the Run method and the Jump method, there are some of the same content (the trainer gives commands and rewards), and the content is not completely abstract, that is, it cannot be handled according to OOP programming ideas. Situations like this can also be found in many areas of our programming, such as logging, performance statistics, security control, transaction processing, exception handling, and so on. But how can such a situation be solved? This introduces the idea of AOP programming.
3. Introduction to AOP
AOP is the abbreviation of Aspect oriented programming, that is, aspect-oriented programming, which is a kind of technology that can be implemented dynamically and uniformly adding function without modifying the source code in the way of precompilation and runtime dynamic Proxy.