Talking about understanding IOC thought

The two most classics in the Spring framework are IOC and AOP. What is IOC (Inversion of Control)? Inversion of control, in simple terms, is to hand over the actions of controlling entity beans to the Spring container for management. To put it simply, for example, if you want to use a class before, you must new one, but if you use Spring, you can directly use @Autowired annotation or use xml configuration to directly obtain this object, and you don’t need to care about its life cycle. Etc. You don't need to create an object yourself.

Insert picture description here
If I have not used IOC before, then the creation and assignment of these objects are created by ourselves. The following simply demonstrates that if the above four objects depend on, then we must create objects and assign values ​​without IOC. There are only four objects, so once the project is big, there are hundreds of objects, if you still write like this, then it will definitely be a disaster.

对象A a = new 对象A();
对象B b = new 对象B();
对象C c = new 对象C();
对象D d = new 对象D();
a.setB(b);
a.setC(c);
b.setD(d);
c.setD(d);

Therefore, in Spring, all objects are unified into the Spring container for management through IOC, so it is much simpler. The above code for instantiating objects does not need us to write.

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_46011971/article/details/107229195