Dependency Injection for Procedural Programming

后端 未结 5 756
野性不改
野性不改 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-13 23:50

    A only needs to call B1 and B2. It does not need to know about anything at the C level.

    You could inject a different dummy versions of functions B1 and B2 into A for the purpose of testing A.

    This isolates A from needing the whole structure and means you can test each function in isolation.

提交回复
热议问题