Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are "Dependency Inversion" and "Design to Interfaces" the same principles?

Do the "Dependency Inversion Principle" (DIP) and "Design to Interfaces Principle" express the same principle? If not, what would be the difference?

EDIT

To clarify and narrow down the context a bit: by interface I mean a programmatic interface, like a Java interface or a pure abstract base class in C++. No other 'contracts' are involved.

like image 961
eljenso Avatar asked Mar 03 '09 12:03

eljenso


People also ask

Is Dependency Inversion a design pattern?

Dependency inversion principle is one of the principles on which most of the design patterns are build upon. Dependency inversion talks about the coupling between the different classes or modules.

Is the dependency inversion principle the same as dependency injection?

The Inversion of Control is a fundamental principle used by frameworks to invert the responsibilities of flow control in an application, while Dependency Injection is the pattern used to provide dependencies to an application's class.

Which technique is commonly used to implement the dependency inversion principle?

Dependency Injection is an implementation of Dependency Inversion Principle. One of the ways to achieve Open-Close Principle is to use Dependency Inversion Principle. High-level modules in DIP are modules that appear on the higher part of the UML diagram and depends on the abstraction layer.


1 Answers

I just wanted to pitch in and quote Derek Greer on another question very similar to this one, since it does answer this question nicely, in my opinion.

"What the Dependency Inversion Principle does not refer to is the simple practice of abstracting dependencies through the use of interfaces (e.g. MyService → [ILogger ⇐ Logger])."

While this decouples a component from the specific implementation detail of the dependency, it does not invert the relationship between the consumer and dependency (e.g. [MyService → IMyServiceLogger] ⇐ Logger)."

like image 85
GR7 Avatar answered Oct 14 '22 06:10

GR7