Play Spring MVC (i)---control inversion (Dependency injection)

Source: Internet
Author: User

The core of spring is control inversion, what is control inversion? A brief comment on his own humble opinion, there are improper places also hope that you point out.


Control inversion (IOC), also called Dependency Injection (DI), is actually a concept of two words.

Control reversal, what is the control being reversed? Martin Fowler concludes that " dependent object Acquisition" has been reversed .


What is a "dependent object"? in most cases, Java requires the cooperation of multiple classes to implement some kind of business logic, and each object needs a reference to the object he works with, the object that he works with is its "dependent object".


If we want to refer to other objects, we first have to instantiate the object, that is, to new an object, then there must be a coupling between the two classes of code. Although the use of methods such as Factory mode can alleviate this problem, it is not possible to fundamentally solve the problem of coupling between the code. The IOC was created to solve this problem by removing the coupling from the code and putting it into a unified XML file, which was formed by a container when needed, by injecting the required interface implementation into the class that needed it, which might be the source of the "dependency injection" argument.


So, to put it simply, control reversal is " when you need to reference an object, you give the configured XML the operation of the instantiated object that should have been controlled by you, and then inject you into it, reducing the coupling between the code ."

Play Spring MVC (i)---control inversion (Dependency injection)

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.