Home  >  Article  >  Java  >  What does dependency injection mean?

What does dependency injection mean?

hzc
hzcOriginal
2020-06-29 15:30:006958browse

Dependency injection means that when the program is running, if you need to call another object for assistance, you do not need to create the callee in the code, but rely on external injection. Spring's dependency injection has a negative impact on the caller and the callee. The caller has almost no requirements and fully supports the management of dependencies between POJOs.

What does dependency injection mean?

#Spring can effectively organize objects at each layer of J2EE applications. Whether it is an Action object in the control layer, a Service object in the business layer, or a DAO object in the persistence layer, they can all be coordinated and run organically under Spring's management. Spring organizes objects at each layer together in a loosely coupled manner. Action objects do not need to care about the specific implementation of Service objects. Service objects do not need to care about the specific implementation of persistence layer objects. The calls to objects at each layer are completely interface-oriented. When the system needs to be refactored, the amount of code rewriting will be greatly reduced.

Everything mentioned above is suitable for Spring's core mechanism, dependency injection. Dependency injection allows beans to be organized together through configuration files instead of being coupled together in a hard-coded manner. Understand dependency injection.

Dependency Injection and Inversion of Control are the same concept. The specific meaning is: When a role (perhaps a Java instance, the caller) needs the assistance of another role (another Java instance, the callee), in the traditional programming process, it is usually created by the caller An instance of the callee. But in Spring, the work of creating the callee is no longer done by the caller, so it is called inversion of control; the work of creating the callee instance is usually done by the Spring container, and then injected into the caller, so it is also called dependency injection.

Whether it is dependency injection or inversion of control, it shows that Spring uses a dynamic and flexible way to manage various objects. The specific implementations between objects are transparent to each other.

Recommended tutorial: "java tutorial"

The above is the detailed content of What does dependency injection mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn