@@ -49,6 +49,7 @@ have any feedback or suggestions for improvement!
49
49
- [ Encapsulate What Changes] ( #encapsulate-what-changes )
50
50
- [ Interface Segregation Principle] ( #interface-segregation-principle )
51
51
- [ Command Query Separation] ( #command-query-separation )
52
+ - [ Dependency Inversion Principle] ( #dependency-inversion-principle )
52
53
- [ SOLID] ( #solid )
53
54
54
55
### Test
@@ -644,6 +645,42 @@ Resources
644
645
- [ Command Query Separation (wikipedia.org)] ( https://en.wikipedia.org/wiki/Command%E2%80%93query_separation )
645
646
- [ Command Query Separation (martinfowler.com)] ( https://martinfowler.com/bliki/CommandQuerySeparation.html )
646
647
648
+ ## Dependency Inversion Principle
649
+
650
+ Dependency Inversion is the strategy of depending upon interfaces or abstract
651
+ functions and classes rather than upon concrete functions and classes.
652
+ Simply put, when components of our system have dependencies, we don’t want to
653
+ directly inject a component’s dependency into another. Instead, we should use a
654
+ level of abstraction between them.
655
+
656
+ ** DIP** is the D in [ SOLID] ( #solid ) .
657
+
658
+ Why
659
+
660
+ - By decoupling the high-level modules from the low-level modules, the
661
+ high-level modules become more reusable and maintainable.
662
+ - Facilitates unit testing by allowing the use of mock objects, enabling
663
+ isolated testing of modules.
664
+ - Reduces the risk of breaking the system when changes are made.
665
+ - Allows adding new implementations without changing the existing code,
666
+ enhancing the system's extensibility.
667
+ - Concrete classes change frequently, while abstractions and interfaces change
668
+ much less.
669
+
670
+ How
671
+
672
+ - Define interfaces to capture behavior and use them to define the dependencies
673
+ of a class.
674
+ - Depends on abstractions, not on concretions.
675
+ - Using patterns like Factory, Service Locator, and Dependency Injection.
676
+ - Use the [ Inversion of Control] ( #inversion-of-control ) principle.
677
+
678
+ Resources
679
+
680
+ - [ SOLID — Dependency Inversion Principle] ( https://medium.com/@inzuael/solid-dependency-inversion-principle-part-5-f5bec43ab22e )
681
+ - [ Dependency inversion principle (wikipedia.org)] ( https://en.wikipedia.org/wiki/Dependency_inversion_principle )
682
+ - [ System Design: Dependency Inversion Principle] ( https://www.baeldung.com/cs/dip )
683
+
647
684
## SOLID
648
685
649
686
A subset of programming principles:
@@ -652,7 +689,7 @@ A subset of programming principles:
652
689
- [ Open/Closed Principle] ( #openclosed-principle )
653
690
- [ Liskov Substitution Principle] ( #liskov-substitution-principle )
654
691
- [ Interface Segregation Principle] ( #interface-segregation-principle )
655
- - Dependency Inversion Principle
692
+ - [ Dependency Inversion Principle] ( #Dependency-Inversion-Principle )
656
693
657
694
## FIRST principles of testing
658
695
0 commit comments