top | item 23779075

(no title)

alecbenzer | 5 years ago

> Loosely coupled code is also easier to reason about and easier to refactor.

Can you expand more on this? I think this is where the author would disagree.

E.g., how is the code easier to reason about or refactor having introduced a location service interface that has only one one implementation?

discuss

order

projektfu|5 years ago

Suppose you have a unit that makes a couple of api calls to set itself up, then performs a computation, then does some sort of storage. Thinking about how you would test this might lead you to an inversion of control approach, and you might isolate side effects. The storage provider might get passed in, both to make it easy to mock, and to reduce coupling and surprise.

alecbenzer|5 years ago

I meant expand on how those things make code easier to understand, not why unit testing causes you to adopt them.