What is IOC = inversion of control and dependency injection )?
Beginners who are new to these concepts are confused. Just as I saw these terms for the first time, I was embarrassed ...... The IT industry is eye-catching, and every new vocabulary is so awesome. Fortunately, we also have the Internet, the most extensive source of information.
IOC is controlled by containers.ProgramBetween, rather than traditional implementation, by the programCodeDirect control. This is the concept of "control reversal": control is transferred from application code to external containers, and control is transferred.
When the industry is clamoring for IOC, the master Martin Fowler also spoke up to post a classic articleArticle"Inversion of control containers and the dependency injection pattern" is the name of IOC. So far, IOC has a new name: "dependency injection )".
Compared with IOC, "dependency injection" is indeed a more accurate description of this ancient and fashionable design concept. According to the name, dependency injection is the dependency between components determined by the runtime of the container. In the image, the container dynamically injects a dependency into the component.
A simple example: one IBM T40 laptop, one USB hard disk, and one USB flash disk. A laptop is connected to a peripheral storage device through a pre-specified interface (USB). For a laptop, only user-specified data is sent to the USB interface, it is determined by the USB device currently connected. Before the USB device is loaded, it is impossible for the notebook to predict which device the user will connect to on the USB interface. Only after the USB device is connected will the dependency between the devices begin to form.
according to the preceding description about the dependency injection mechanism, the runtime (system boot, USB device loading) is performed by the container (Windows operating system running in the notebook) inject dependencies (laptops rely on USB devices for data access) into components (Windows File Access Components ).
This is a version of the dependency injection mode in the real world.