A Ioc/di
1. Concept Machine principle
Ioc:inversion of control inversion is a design idea that the container controls the creation and management of external resources required by the application and then forwards it back to the application. The creation and maintenance of objects and their dependent objects do not need to be implemented in the application and will be delegated to the IOC container for management. In the traditional development, we create the dependent objects inside the object and inject the current object, and complete the maintenance of the dependency; for the IOC, it emphasizes the initiative to be passive, the IOC container is responsible for the creation and lookup of dependent objects, the IOC container to inject composite objects, We only need to maintain dependencies between objects in the relevant configuration file.
Di:dependency injection, or "dependency injection". In fact, the IOC and DI are two different representations of the same concept, and the application relies on the external objects provided by the container, which injects the external resources it relies on into the application at run time, and when an object is called, the object it relies on is container injection.
2. Advantages
First, the centralized management of resources, the realization of the resources can be configured and easy to manage, reduce the complexity of object relationship maintenance.
The second is to reduce the dependence on the use of resources, which is what we call the coupling degree.
Two AOP
1. Concepts and principles
AOP leverages a technique called "crosscutting" that splits the encapsulated object inside, encapsulating common behaviors that affect multiple classes into a reusable module and names it as an aspect (Aspect). The so-called "aspect", in short, is the part of the logic that does not relate to the business but is called together by the business module. In order to reduce the repetitive code of the system, reduce the coupling between the modules, and facilitate the maintenance of the system.
Using "crosscutting" techniques, AOP divides software systems into two parts: core concerns (business logic) and crosscutting concerns (common logic, or aspect). The main process of business process is the core concern, and the part that has little relation is the crosscutting concern. Crosscutting concerns are characterized by the frequent occurrence of many of the core concerns, which are essentially similar throughout the site. such as authority authentication, logging, transaction processing, debug management, performance testing. The role of AOP is to separate the various concerns in the system, separating the core concerns from the crosscutting concerns.
2. How to Implement
The techniques for implementing AOP are divided into two major categories:
The first is to use dynamic agent technology, using interception of messages to decorate the message to replace the original object behavior of the execution;
The second is the use of static weaving, the introduction of a specific syntax to create "facet", so that the compiler can be in the compilation of the "aspect" of the code.
3. Advantages
①. The code for crosscutting concerns is concentrated in one piece, no longer scattered among the various business components, and there is no duplication of code;
②. Core modules focus only on the core functions of the Code, and the General module separation, the module between the decoupling of the reduced.
Spring Ioc/di and AOP principles