How I discovered Dependency Inversion…

One of the first thing that made me think that architecture mattered was when I discovered what Dependency Inversion was all about.

First I was generally mixing Dependency Inversion and Dependency Injection. For sure you better associate them but they can be used independently if you want. To me Dependency Injection was about : I want to have a class and be able to use it with what I want and I want to be the master of this. It was also the D letter in the acronym SOLID (this is wrong if you don’t know… 🙂 D is for Dependency Inversion). I was even pushing this during interviews and I was fully wrong…

I was also using lot’s of interfaces (sometimes called protocols in languages like Swift). At that time I was already “senior” enough and I knew that using interfaces was a nice way to make Unit Tests (or pretend at least), a nice way to look/sound smart (or pretend at least) and a nice way to decouple my code from the one of other developers around me. Of course, lots of developers were saying : “this guy does not know what is doing. He’s generating tons of over-engineering stuff…”. On the other hand, some of them (sometimes the same one) were impressed because I was able to work with their code before it was even produced and I could deliver features that were “supposedly” depending on other features (and I could tell where those features were crashing). I could even develop without knowing some final frameworks that the client wanted to use.

Of course I could not communicate what I was doing because I didn’t even know what I was doing (at least the names behind the concepts). And then one day I crossed one guy. He looked at my code and said : “Nice use of dependency inversion !”. I said : “Nice use of what ? You mean Injection ?”. He said : “So you do things and you don’t know their names ? This is dependency inversion. You revert your dependance to this framework and this is nice. It can be used with injection but in your case it’s just an inversion…”. There was suddenly light in the room. (he also told me that it was the D in SOLID and that I should stop pretending to do SOLID without knowing SOLID…).

I will say many more things on this in some other posts as to me : “All is about where to use Dependency Inversion”

Leave a Reply

Your email address will not be published. Required fields are marked *