Joke Collection Website - Talk about mood - How to understand the spring ioc container

How to understand the spring ioc container

. 1, what is IoC?

IOC—-control inversion, that is, "control inversion", is not a technology, but a design idea. In Java development, Ioc means giving the object you designed to container control, rather than the traditional direct control object. How to understand the International Olympic Committee? In order to understand the IOC well, the key is to find out "who controls who, what, why it is inversion (it should be positive inversion) and what aspects of inversion". Then let's analyze it in depth:

● Who controls who and what: In traditional Java SE programming, we directly create objects inside the objects through new, which is the initiative of the program to create dependent objects; Ioc has a special container to create these objects, that is, IoC container controls the creation of objects; Who controls who? Of course, the IoC container controls the object; Control what? That is, it mainly controls the acquisition of external resources (not only objects including files, etc.). ).

● Why is it reversed? What aspects are upside down? Where there is a reversal, there is a forward rotation. The traditional application directly obtains the dependent object by its own control in the object, that is, forward rotation; Inversion is to create and inject dependent objects with the help of containers; Why is it backwards? Because the container helps us find and inject the dependent object, the object only passively accepts the dependent object, so it is inverted; What aspects have been reversed? The acquisition of related objects has been reversed.