Before asking this question I like to say that this question in stackoverflow is very similar to my question but still the concept is not clear very confusing.
I am trying to understand the dependency inversion principle but I could not able to understand it completely?
The below are two point which DIP says
A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend on details. Details should depend on abstractions.
I can able to grasp the first point but I cannot able to get the second point, its look like both are same. After lots of search in stackoverflow & other sites I can able to understand both are trying to say different thing but I could not able to get it.
Let’s consider an example:
Let’s consider SalaryCalculator class [High level module] which is used to calculate the salary of employee. Which uses BonusCalculator [High level module] to calculate the salary as shown below. Since SalaryCalculator is using BonusCalculator it’s violating the first point of “High-level modules should not depend on low-level modules. Both should depend on abstractions”.
So we introduced abstraction between both as shown below:
Here details [Low & High level Modules] is dependent on Abstraction & abstraction is not dependent on details. So in DIP what that second point is trying to tell? If both are same why it is made as two points?
If some one gives me an code example , that will be very useful.