NOTE
What It Is
IOC delegates object creation and management to a container, from which business code obtains dependencies. These notes compare that arrangement with manual construction.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Explanation of IoC
Inversion of Control.
Before IoC, when we wanted to use an object, we first had to create it ourselves with new.
With Spring, Spring creates it for us and puts it into the container. We obtain the object directly from the container and use it.
2. Implementation Principle
Factory pattern + reflection + XML parsing.
Scan all XML files, parse them with dom4j, then create Beans and put them into a map in the factory. When we call getBean, the Bean is obtained from that map.
3. Benefits of IoC
The goal is to reduce coupling.
If A uses B and directly creates B with new, A and B are highly coupled.
After introducing a factory, the factory and B become highly coupled.
After introducing XML parsing, the factory class uses dom4j to parse XML and then uses reflection to create objects.
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub