Search code examples
oopdesign-patternssolid-principles

Dependency Inversion Principle's second statement elaboration


Following two statements are core of the Dependency Inversion Principle(DIP):

"High-level modules should not depend on low-level modules. Both should depend on abstractions." "Abstractions should not depend on details. Details should depend on abstractions."

I read different books and article about DIP; all of them explained the first statement but none of them explain the second statement: "Abstractions should not depend on details. Details should depend on abstractions". Please explain what exactly are the meaning of this second statement.


Solution

  • It just means that you don't want to change an abstraction just because a detail has changed because details are likely to change.

    Because both high-level and low-level modules depend on abstractions, they will also have to be changed whenever a detail has changed. This would obviously be undesirable.