Dependency Injection for Procedural Programming

后端 未结 5 673
野性不改
野性不改 2021-02-13 23:00

Suppose I\'ve decided to write a large application in C, or any other procedural programming language. It has functions with call-dependencies that look like this:



        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-13 23:54

    You can do proper unit testing of B1, B2 and A without DI. Just like the leaf functions, B1 and B2 has valid inputs and outputs, and you test those, same with A. That B1 can use C11 and C12 internally to help you fulfill its unit tests doesn't mean they have to be injected in cases where you don't need that flexibility.

提交回复
热议问题