Inversion of Control visualized
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 :).
Before
Consider the simple example of a circular dependency:
- Module
Auses moduleB - Module
Buses moduleA
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.
After
Now we use Inversion of Control to break free of this circular dependency:
- Module
Auses<<B>>(which is moduleB’s interface) - Module
Buses/implements<<B>>(is a specific implementation of) - Module
Buses moduleA
Notice that A knows nothing about B (only about the interface <<B>>).

Comments