Monday, November 23, 2015

Dependency Injection vs Dependency Inversion Principle

Dependency Injection vs Dependency Inversion Principle


Both are two different things. Dependency Injection is a design pattern that implements Inversion of Control design principle. So now the question is what is Inversion of Control principle.

Inversion of Control :- IOC is a design principle in which custom-written portion of computer program recieve(not fetch, means library will send) the flow of control from a generic, reusable library. It is opposite to normal design in which custom code, makes call to generic library to get flow of control.

Dependency Inversion principle :- According to uncle Bob, DIP is in which high level module should not be dependent upon the low level module. So for avoiding this, both high level and low level module should be dependent upon abstraction. For example eclipse should not be dependent upon the plugin.

Because if high level code is dependent upon low level module, then it will add compile time dependency in high level module.