Is there any hard data about the value of control inversion or dependency injection?

I read a lot about IoC and DI, but I'm not sure that you will gain much by using them in most situations.

If you write code that requires plug-in components, then yes, I see the value. But if you don’t do this, I wonder if the change in class dependency to interface really gets you anything but more typing.

In some cases, I can see where IoC and DI help with mockery, but if you are not using Mocking or TDD, then what is the value? Is this the case of YAGNI?

+3
source share
3 answers

, - , .

-, DI ( SOLID), TDD. , TDD, , , , .

, - , . fooobar.com/questions/34162/....

, , , , . , , SRP.

, , . (.. ), , . , .

, . YAGNI, , , . - , .

DI, . . , , , . , ( ), . , , Singleton, .

, . , (- + ).

: , .

+2

DI . , . , , , , .

- , , .

, , , . .

DI , . , DI, . - , , . .

+1

.

Java, ( 50 ).

, . , - , . , , , . , .

The second component that I developed from scratch, and used dependency injection (not knowing about it at that time). That is, I had one factory, which built all the objects and introduced them in order to know the base. Adding another dependency was simple, just add it to the factory constructor and object constructor (or add an installer to avoid loops). No need to touch unrelated code.

0
source

Source: https://habr.com/ru/post/1705106/


All Articles