DEV Community

Cover image for What inverts in the dependency inversion principle?

What inverts in the dependency inversion principle?

Rui Figueiredo on March 01, 2017

Have you ever wondered why the dependency inversion principle is named the way it is? The dependency inversion principle is often described as "D...
Collapse
 
dvanherten profile image
Dave van Herten

Could it be this:

Before: Copier will break if keyboard renames the Read method.
After: Keyboard will break if IReader interface changes (on behalf of the Copier's needs).

Dependencies are inverted.

Collapse
 
thefuquan profile image
Redouane M. BOUDELLA

That was a good read.

I think we can say that before the inversion, high level module depends on low level modules coz the copier should know about the keyboard and printer modules in order for it to call their functions, and the low level modules may know nothing about the high level ones.

After the inversion, the high level modules introduces a protocol, a contract aka an interface that the low level modules should know about in order to implement them, that is the inversion as the high level modukes now may/should know nothing about the low level ones