O
O
Oleg2015-06-26 12:15:10
Java
Oleg, 2015-06-26 12:15:10

What are the goals of Dependency Injection?

As far as I know, DI is usually used for testing. What other use cases are there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2015-06-26
@wani

DI is a way to create interfaces where they were not there before, but they are suddenly needed now. Interfaces are introduced not just like that, but to solve some problem. Moving away from programming and taking the situation with hardware as an example, we will understand that people have greatly benefited when they decided to divide computing facilities into the motherboard, CPU, RAM, Hard disk, etc. Yes, they complicated it by introducing interfaces, but at the same time increased ease of use and increased speed of development. The speed of manufacturing parts has increased due to the fact that a single component is easier to manufacture than a whole system! Moreover, the component can be with different characteristics, price and manufactured by many companies at different production facilities. Returning to DI : the programmer benefits from the fact that it is now much easier to install a new component. For example, by giving an interface to a programmer on the side, by giving him unit tests (as a "live" TK), you get extra time, because. while the component is being sawed by a third-party programmer, you can cut another part of the system, and you can accept the work after passing unit tests and be sure that this is what you wanted, unless, of course, the unit tests were well thought out;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question