The Hollywood Principles-spring IOC container

Source: Internet
Author: User

The concept of the IOC container, before learning ssh, has been exposed. But at that time it was just a concept that was very difficult to understand. In fact, it is not difficult to understand, but I did not stop to properly summarize it.

IOC(Inversion of Control) Brief Introduction:

Inversion of control "is not a technology. But a thought. An initiative to provide the services of the idea. The so-called IOC, which is responsible for controlling the life cycle of objects and the relationship between objects by spring, runs counter to our traditional direct control over objects.


In the traditional program development, the completion of a business logic requires at least two or more than two objects to assist. Usually one object uses another object. Objects are created directly inside the object through new. The object has been created by the program to be active.

But this means that the current module is tightly coupled with the object it relies on. But in fact, all we need is to invoke a service provided by the dependent object. But think about the assumption that there is a way for these services to be delivered proactively to meet our needs. We don't have to be so laborious. The IOC is a simple principle that proactively helps create and inject dependent objects. For example, with:


Traditional program development: assembling objects----actively creating objects




IOC container: Production line-Create and assemble objects, direct client Access



The idea of an IOC container is, in fact, very easy, an intermediary that provides certain services, All the information is first registered in this institution. Tell someone what you are. What do you need? Other people can provide you with services, and also make you as a service to other parties.

di (Dependency Injection):

Spring's IOC container is primarily implemented using DI, without the need for active lookups, During the execution of the system, the object is dynamically provided with the other objects it needs. For example, Class A needs to manipulate the database, and once we always write code in Class A to create a connection object, with spring. We just need to tell spring. A need a connection. How is this connection object created? When was it created? Class A does not need to be concerned, and when the system executes, Spring creates a connection object at the appropriate time. Like an injection, inject into Class A.

Dependency Injection is implemented primarily through reflection mechanisms, as described in the first two blogs. At the same time, the IOC provides three methods of dependency injection, each of which is constructed method injection, setter method injection, and interface method injection.

Spring's IOC container design idea is the same as the Hollywood principle: Don ' T call us, We will call you!

  That is, you do not need us, we will find you!



Hollywood principles-spring IOC container

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.