Dependency Injection
- by having familiarity with the
io.Writerinterface - we were able to use the
bytes.Bufferin our tests -
and the
use other writersin the standard library to use our function in a command line or web server -
test code - if you can't test a function easily, it's usually because of dependencies being hard wired into a function or global state
- dependency injection motivates you to inject a dependency via an interface to mock out the resource which enables testing
separate concerns- decouple where data goes from how it is generated
allow code ot be reusable