TDD is impossible without Inversion of Control and DIP

Get it? Inversion 🤧

“IoC is all about inverting the control. To explain this in layman’s terms, suppose you drive a car to your work place. This means you control the car. The IoC principle suggests to invert the control, meaning that instead of driving the car yourself, you hire a cab, where another person will drive the car. Thus, this is called inversion of the control — from you to the cab driver. You don’t have to drive a car yourself and you can let the driver do the driving so that you can focus on your main work.”

If you were at any point confusing the terms dependency or dependent, an easy pointer to help remember: If A is dependent on B, then B is a dependency of A. Still confused?! I know I am(linguistics horror) Essentially anything that is required to run A is a dependency of A :).

Well you need loosely coupled things for TDD to be effective. And how do we get that? We get everything that is being used in a thing and move it to another method. So that’s deal, See, Inversion of Control is a principle, a paradigm, you can use it anywhere and everywhere. Not just with code :).

So if you have a data access layer(ex: a mongoose database layer) and a node.js business logic layer. Then you want to seperate out the data access parts in the business logic layer into a seperate class. Only then can you accurately and precisely separate concerns and then subsequently Test.

Sometimes i’m wordy, Check the linked article for a great example saying why (and how) your data access is probably tied to your business logic and why you should change it!

What’s DIP? I’ve got an article on that too!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store