- Hands-On Dependency Injection in Go
- Corey Scott
- 160字
- 2021-06-10 19:17:48
How does this relate to DI?
As we have seen, the ISP helps us to break down interfaces to logically separate parts, with each part providing a particular feature—a concept sometimes referred to as a role interface. By leveraging these role interfaces in our DI, our code becomes decoupled from the concrete implementation of the inputs.
Not only does this decoupling allow parts of the code to evolve separately, but it also tends to make it easier to identify test vectors. In the previous example, it's easier to scan through the inputs one at a time and consider their possible values and states. This process might result in a list of vectors like the following:
Test vectors for the value input include:
- Happy path: Returns a valid value
- Error path: Returns an empty value
Test vectors for the monitor input include:
- Happy path: Does not return a done signal
- Error path: Immediately returns a done signal