Dependency inversion principle

From Wikipedia, the free encyclopedia

Jump to: navigation, search

The Dependency Inversion Principle (DIP) is sometimes regarded as a synonym for inversion of control. However, dependency inversion can be thought as a more simplistic constituent of the larger concept of inversion of control. [1]. This principle seeks to "invert" the conventional notion that high level modules in software should depend upon the lower level modules; instead, both high and low level should depend upon a shared abstraction. Software consultant Robert C. Martin stated the principle this way:

High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.

The advantage of a design with Dependency Inversion Principle in mind is that you do not have to develop the lower level modules before developing the higher level modules. Thus a top-down approach is possible in both design and development.

The technique through which the principle is applied is called Dependency injection. Objects in the lower layers are injected into the higher level objects. The result is that components are less tightly coupled, and there is a high degree of separation of concerns. The individual components are more easily testable and the higher level objects can be tested with mock objects in place of lower level services.


[edit] DI and Unit testing

Because the higher-level components are not coupled with the hard-to-simulate low-level functionality, DI is complementary to the unit testing strategy using automated unit test generation and execution.[2]

[edit] References

  1. ^ Dependency Inversion Principle EventHelix, Retrieved on 13 February 2008
  2. ^ TDD Design Starter Kit - Dependency Inversion Principle, Retrieved on 13 February 2008

[edit] See also

[edit] External links

Personal tools