Basic concepts of Springloc and aop

What are Inversion of Control and Dependency Injection?

Inversion of control (IoC) and dependency injection (DI) are commonly used programming paradigms in software development.
They greatly improve code maintainability and reusability and simplify code structure.

What is Inversion of Control (IoC)


Inversion of control is a programming model that transfers control in the application to the container. The
user specifies the resources it needs for the container, and the container completes specific object creation and
allocation of external calling resources. In the control inversion mode, object dependencies
are managed by a third-party container (such as the Spring framework) rather than by the program itself.

What is Dependency Injection (DI)

Dependency injection is another programming paradigm that replaces resources that need to be implemented through calls with
injected dependencies (often called parameters). These dependencies are usually
provided by the object that implements the object. The idea of ​​dependency injection is to decouple the calling and implementation of dependencies to achieve decoupling
and maintainability. When using dependency injection, you need to provide a way to inject instances
.


Advantages of Inversion of Control and Dependency Injection


(1) Simplify coding. Inversion of control and dependency injection modes can transfer resource and object references to third-party containers and dependency parameters respectively, thereby saving code for instance building and avoiding
writing a lot of repeated code.
(2) Improve reusability. Inversion of control and dependency injection patterns can
decouple the creation of objects and resources from dependencies, which will improve code reusability.
(3) Provide testability. Using the inversion of control and dependency injection modes, you can effectively manage interfaces
and implementations and simplify the writing of test suites. When the implementation of the interface changes, you can modify the
corresponding dependencies without modifying the written test code.


Summarize


Inversion of control and dependency injection are commonly used programming patterns in software development. They can simplify the code
structure, improve code maintainability and reusability, and provide testability. They are
important concepts in software development and are widely used.
 

What is AOP?

aop means unified maintenance of program functions through precompilation and runtime dynamic agents. aop stands for aspect-oriented programming. In the Spring framework, aop is a very important function. AOP can be used to isolate various parts of the business logic, thereby reducing the coupling between the various parts of the business logic, improving the reusability of the program, and improving the efficiency of development.

What is the core idea of ​​AOP?

AOP (Aspect-Oriented Programming) is a programming paradigm that divides the functionality of an application into core business and
horizontal concerns (such as logging, performance testing, permission control, etc.). The core idea of ​​AOP is to
extract horizontal concerns from the core business so that horizontal functions can be better reused and modified. In AOP,
horizontal concerns are called aspects, and core services are called connection points. By defining common horizontal functions on aspects
we can easily apply them to multiple join points making the code easier to maintain and understand.

What are the enhanced processing types and characteristics of AOP?

Enhancement type Features
Before Pre-enhancement processing, weaving enhancement processing before the target method
AfterReturning Post-enhancement processing, weaving in the enhancement processing after the target method is executed normally (no exceptions occur)
AfterThrowing Exception enhancement processing, weaving in enhanced processing after the target method throws an exception
After Final enhancement processing, regardless of whether the method throws an exception, will be woven into the end of the target method.
Around Surround enhancement processing can be woven into the enhancement processing before and after the target method. Can control whether the target method is executed


 

Guess you like

Origin blog.csdn.net/m0_65491952/article/details/131342362