The Hollywood Principles-spring IOC container

Source: Internet
Author: User

The concept of the IOC container, before learning ssh, has been exposed. But then it was just the idea that it was hard to understand. In fact, it is not difficult to understand, but I did not stop to make a good summary of it combed.

Introduction to the IOC(inversion of Control) :

Inversion of control "is not a technology, but a thought, an initiative to provide services. 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 traditional program development, the completion of a business logic requires at least two or more than two objects to assist in the completion. Usually an object is to use another object, which is created directly inside the object through new, and the program is actively going to create the object. But this means that the current module is tightly coupled with the object it relies on. But in fact, all we need to do is invoke a service provided by the dependent object, but think about how it would be less strenuous if there was some way to get these services to come up and meet our needs. The IOC is a simple principle that proactively helps create and inject dependent objects. Such as:


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 simply that it is an intermediary that provides certain services, all of which are first registered in this institution, and tell others what you are. What do you need? Others can provide you with services, and also make you as a service to other parties.

DI (Dependency Injection):

Spring's IOC container is implemented primarily in DI mode, and does not require active lookups, and dynamically provides other objects that it needs to an object during the system's operation. For example, Class A needs to manipulate the database, and before we always write code in Class A to create a connection object, with spring, we just need to tell Spring,a that a connection is needed. How is this connection object created? When was it created? Class A does not need to be concerned, when the system is running, Spring creates a connection object, like an injection, into Class A.

Dependency injection is implemented primarily through reflection mechanisms, which have been introduced in the first two blog posts. At the same time, IOC provides three kinds of methods of dependency injection, namely, construction 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'll call you! that is, you do not have to find us, we will find you!

The 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.