Tuesday, July 13, 2010

Dependency Inversion Principle

"traditional software development methods, such as Structured Analysis and Design, tend to create software structures in which high level modules depend upon low level modules, and in which abstractions depend upon details." Robert C Martin, 'The Dependency Inversion Principle', C++ Report, 1996

Top-Down design causes developers to create code in which high level business rules depend on low level functions like IO. This means the business functionality is not reusable because it is coupled to the IO functionality.

Adding conditional statements so that the business function can use one set of IO routines in one case and another set in a second case soon this becomes difficult to manage. This strategy of modifying code to make it dependent on even more low level routines violates another principle, the Open Closed Principle which Mr. Martin also wrote about.

Of course, any number of people will say that one design is as good as another, that it is okay to duplicate the business logic and couple the new copy to a different set of low level components. Unfortunately, it is rare that one person can change the mind of another as evidenced by today's news: Researchers at the University of Michigan found that when misinformed people were exposed to facts, they rarely changed their minds and they often became even more strongly set in their beliefs.

This phenomenon was commented on by Darwin in 1871:
Ignorance more frequently begets confidence than does knowledge