Spring core idea IOC, AOP

Spring core idea IOC, AOP

Note: IOC and AOP are not proposed by spring, they existed before spring, but they are more theoretical. Spring has implemented these two ideas at the technical level (Java)

IOC

1. What is IOC?

IoC Inversion of Control (Inversion of Control/Inversion of Control), note that it is a technical idea, not a technical realization description thing: the creation and management of objects in the Java development field.
Traditional development methods : similar to class A Relying on class B, there is often a new object of B in class A.
This is like finding an object: 1. Confirm the target (whether you are a chat or a favorite girl) 2. Establish a link (chat interaction, familiar with each other) 3. 、Dating (meeting or dating movies, or whatever else it’s up to you) 4. Success or failure (this can’t be forced, don’t care too much...) The
above means that the traditional development model requires us. Involved in every detail, every step, etc.; that is, do it yourself

The development method under IoC thinking : we don’t need to go to the new object by ourselves. Instead, the IoC container (Spring framework) helps us instantiate the object and manage it. Which object we need to use, just ask the IoC container.
We have lost a right (the right to create and manage objects) and got a benefit (without considering the creation and management of objects, etc.).
This is like finding an object. We don’t have to do it ourselves. If you need an object, go to the "matching agency" and let them help us match. This "matching agency" is the spring container. What is the need? Just ask him if you want it.
Why is it called inversion of control?
Control: refers to the
right to create (instantiate, manage) objects. Reversal: control is given to the external environment (spring framework, IoC container)

Insert picture description here

2. What problems did IOC solve?

IoC solves the coupling problem between objects

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-NB6uD9fp-1603956783711)(C:\Users\yqhou\AppData\Roaming\Typora\typora-user-images\ image-20201029152400897.png)]

3. The difference between IOC and DI

DI:
How to understand Dependancy Injection :
IOC and DI describe the same thing, but the degree is different

Insert picture description here

AOP

1. What is AOP

AOP: Aspect oriented Programming Aspect oriented programming / Aspect oriented programming
AOP is a continuation of OOP, starting from OOP

The three characteristics of OOP: encapsulation, inheritance and polymorphic
oop is a vertical inheritance system

Insert picture description here

OOP programming ideas can solve most of the code duplication problems, but there are some situations that can’t be dealt with. As shown in the following
, duplicate code appears in the same position in multiple methods in the top-level Animal, and OOP cannot solve it.

Insert picture description here

Crosscutting logic code

Insert picture description here

What is the problem with the cross-cutting logic code:

  • Crosscutting code duplication problem
  • Cross-cutting logic code and business code are mixed together, the code is bloated, and maintenance is inconvenient

AOP appeared, AOP proposed a horizontal extraction mechanism in a unique way, which will analyze the cross-cutting logic code and business logic code

Insert picture description here

In the case of code splits easily, so how without changing the original business logic, quiet ⽆ sound logic of the cross-section of the code to apply it to existing industry
business logic, and achieve the original movie-like effect, this is a more ⽐ hard

2. What problem is AOP solving?

Without changing the original business logic, enhance the cross-cutting logic code, fundamentally decouple, and avoid the cross-cutting logic code duplication

3. Why is it called aspect programming?

"Cut": refers to the cross-cutting logic. We can't move the original business logic code. We can only operate the cross-cutting logic code. Therefore, the horizontal cross-cutting logic
"face": The cross-cutting logic code often affects many aspects. Method, each method is like a point, multiple points constitute a
surface , there is a concept of a surface in the

Guess you like

Origin blog.csdn.net/weixin_44796239/article/details/109361296