Dependency Inversion Principle(DIP)
It is a part of SOLID[About] which is a part of OOD and was introduced by Uncle Bob. It is about loose coupling between classes(layers...). Class should not be depended on concrete realization, class should be depended on abstraction/interface
Problem:
//A -> B
class A {
B b
func foo() {
b = B();
}
}
Solution:
//A -> IB <|- B
//client[A -> IB] <|- B is the Inversion
class A {
BIB ib // An abstraction between High level module A and low level module B
func foo() {
ib = B()
}
}
Now A
is not depended on B
(one to one), now A
is depended on interface IB
which is implemented by B
, it means that A depends on multiple realization of IB
(one to many)