ObjectiveRecently learning the spring framework, its core is the IOC container. To master the Spring framework, it is necessary to understand the idea of inversion of control and the way that dependency injection is implemented. Below, we will explore the relationship between control inversion and dependency injection,
Spring is an open source framework, and spring is a lightweight Java development box that emerged in the 2003 The frame, created by Rod Johnson. In short, spring is a layered javase/eefull-stack (one -stop) lightweight , open-source framework that is primarily used to reduce the coupling between modulesSpring In addition to being able to other functions are also available through the IoC to reduce the coupling between modules. 1, the basic knowledge and principles of the IOC:The background of
I. Fundamentals and principles of the IOC:The background of 1.IoC theory: in the software system with object-oriented method design, the bottom-level implementation is composed of N objects, all the objects through each other's cooperation, finally realizes the system business logic. That is, the coupling between objects in a software system, object A and object B are related, and object B is dependent on object C, so that there is a complex dependenc
forms a dependency. Traditional development is called directly when using other classes, which creates strong coupling, which is to be avoided. The dependency injection borrowing container transfers the dependent object implementation decoupling.
3, injection: Who injected into who? What exactly is injected?
A: Inject the external resources needed by the container to the object
4. Control reversal: Who Controls who?
get an instance of C, and then injects the reverse into Class A.Using the legend to illustrate, first look at the time when there is no Ioc/di, the general Class A using Class C, 7 is shown:Figure 7 General A uses CWhen a Ioc/di container is available, Class A no longer takes the initiative to create C, as shown in 8:Figure 8 Class A is no longer actively creati
instance of C, and then injects the reverse into Class A.
Using the legend to illustrate, first look at the time without Ioc/di, the general Class A uses the C class diagram, as shown in Figure 7:
Figure 7 General a uses C schematic
When a Ioc/di container is available, Class A no longer takes the initiative to create C
Theoretical discovery ProblemsBefore going into detail, we need to make sure that we understand what "IOC control inversion" and "Di Dependency injection" are and what problems can be solved, which are clearly explained in Wikipedia.
controlling inversion (inversion of con
OrderThe first time I learned the concept of control inversion (inversion of controls) was when learning the spring framework. IOC and AOP, as the two characteristics of spring, are naturally going to learn well. and Dependency Injection (Dependency injection, short di) makes me confused for a long time, always trying not to understand the connection between them
OrderThe first time I learned the concept of control inversion (inversion of controls) was when learning the spring framework. IOC and AOP, as the two characteristics of spring, are naturally going to learn well. and Dependency Injection (Dependency injection, short di) makes me confused for a long time, always trying not to understand the connection between them
baserepository type in the constructor.Now the Ninesky.base project is still dependent on the project ninesky.datalibrary, and there is no decoupling, if you want to remove the dependence of many ninesky.datalibrary to find a way to transfer the interface of the instantiation of the project.V. Inversion of controlControl inversion is the move of dependent creation to the outside of the class. Then we modif
1.Control Reversal(inversion of Control)and Dependency Injection(Dependency injection)Control inversion, the IOC (inversion of control), gives the container the right to assemble and ma
PHP control inversion and dependency injection:
b=new B();$this->c=new C();$this->b->Method();$this->c->Method();//TODO} }class B{public function B(){//TODO}public function Method(){//TODOecho 'b';}}class C{public function
Thank http://blog.xiaohansong.com/2015/10/21/IoC-and-DI/for the map
1. What is control. As shown in the following figure, we see the object in the software system
high coupling phenomenon. The rotation of all gears is controlled by an object., such as Class B.
2. What is control reversal. is used to object
to decouple。
Decoupling between objects that have dependencies with third-party implementations.
1. IntroductionDependency injection and control inversion are intended to enable the decoupling of classes from classes, to improve the scalability and maintainability of the system, and to introduce this concept through an example.2. Case studies1) class coupling under normal conditionsMain.javaPublicClassMain {PublicStaticvoidMain (string[] args) {/**General notation, strong coupling between the main clas
0x1 What is Dependency injectionDependency Injection (Dependency injection) is a process in which a customer class relies on only one interface of the service class and does not rely on a specific service class, so the customer class defines only one injection point. In the process of running the program, the client class does not instantiate the specific service class instance, but the client class's running context or specialized component is responsible for instantiating the service class and
Spring entry-control inversion (IOC) and dependency injection (DI), springioc
1. Inversion of Control and Dependency Injection)
Control Inversion is IoC (Inversion of
Control inversion (Ioc) and dependency injection (DI), iocdi
The IOC is called "Inversion of Control ". Dependency Injection DI, full name "Dependency Injection ".
In software development, to reduce the coupling between modules and classes, we advocate interface-based development, in implementation, we must face the qu
1. Control reversal
Inversion of control (IOC): in short, the Code controller is handed over to the system for control, rather than being inside the code. IOC eliminates direct dependencies between components or modules, makingSoftwareSystem development is more flexible and scalable. The typical application of
class structure, we also need to make corresponding adjustments to Class A, and the independence of Class A is lost, which is inconvenient in the development process, that is, what we say is "taking A whole body ", if two classes are written separately by two people, conflicts often arise at this time...
If you really want to change Class B and Class C, is there A way to change the class A code as little as possible?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.