less than 1 minute read

In this blog post I visualize an important concept called Inversion of Control.

Blatantly stolen from cosmicpython.com, but I like my visualization a tiny bit more because it is more explicit about who implements what.

I want to reproduce it so I really understand it and internalize it :).


Consider the simple example of a circular dependency:

  • Module A uses module B
  • Module B uses module A

These modules are tightly coupled.

In fact, these modules are so tightly coupled they might as well be a single unit!

How do we fix this? Inversion of Control to the rescue.


Now we use Inversion of Control to break free of this circular dependency:

  • Module A uses <<B>> (which is module B’s interface)
  • Module B uses/implements <<B>> (is a specific implementation of)
  • Module B uses module A

Notice that A knows nothing about B (only about the interface <<B>>).