NOTE
Dependency Inversion Principle
What the dependency inversion principle is, why it is needed, and implementation guidance centered on interfaces and abstract classes.
This is a historical learning note and may contain outdated or incomplete understanding.
1. What Is the Dependency Inversion Principle?
High-level modules should not depend on low-level modules.
Program to interfaces, not implementations.
2. Why Is the Dependency Inversion Principle Needed?
Improve extensibility.
3. Implementing the Dependency Inversion Principle
Each class should provide an interface or abstract class whenever possible, or both.
The declared type of a variable should be an interface or abstract class whenever possible.
No class should derive from a concrete class; it should derive from an abstract class.
When using inheritance, follow the Liskov substitution principle whenever possible.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub