"Spring" IOC

Source: Internet
Author: User


The theoretical background of the IOC

Figure 1: In the traditional system, the object is referenced in a graph, in the use of object-oriented design of the software system, its underlying implementation is composed of N objects, all the objects through the cooperation between the final realization of the system's business logic, if we open the rear cover of the mechanical watch, We will see a clear shape similar to Figure 1, with each gear driving the hour, minute and second hand clockwise to produce the correct time on the dial. These gears are coupled to each other to accomplish a task together. In such a gear group, if there is a problem with a gear, it may affect the normal operation of the whole gear set, the coupling relationship between gear group gears is very similar to the coupling relationship between the objects in the software system. As the system becomes larger and the dependencies between objects become more and more complex, architects and designers face more challenges to the design and analysis of the system, and the coupling between objects can be reaching, and the coupling between the system, the module and the object will be reduced, which is the goal of the software engineering pursuit. The idea of IOC theory is to solve the problem that the coupling between objects is high, and the decoupling between objects is realized.

Figure 2 Decoupling process

The idea presented by IOC theory is roughly the same: with the help of a third party to decouple the objects that have dependencies, there is no coupling between the objects. Due to the introduction of a third-party IOC container, so that the object A, B, C, D has no coupling between the gears of transmission all rely on the third party, all the control of all the objects to the third-party IOC container, the IOC container has become the key core of the entire system, it has played a role of the condensate I, Put all the objects in the system together to work.

Figure 3 The ideal system

The four objects have no connection to each other, so that when you implement a, you don't have to think about B, C, and D, and the dependencies between objects are minimized. Every member involved in the development, as long as the realization of their own class is good, and other people do not have any relationship. Let's take a look at the reason why the control reversal takes that name.

Before the introduction of the IOC container, the software system, as shown in Figure 1, object A relies on object B, then object A, when initializing or running to a point, must create object B, or use the B that has already been created, whether it is to create or use object B, the control is all in its own hands, After the introduction of the IOC to the software system, the situation was completely changed, 2, as the IOC container was added, object A and object B lost direct contact, so when object a runs to object B, the IOC container will actively create an object B, injected into the place where object A is needed, by contrast before and after , it is seen that object a gets dependent on the process of object B, from the active behavior to the passive behavior, the control is reversed, this is the name of the control reversal of the origin.

Dependency Injection di

"Spring" IOC

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.