Join Steven Lott for an in-depth discussion in this video Introduction to dependency inversion, part of S.O.L.I.D. Programming Principles.
- View Offline
- The fourth solid design principle I'd like to look at…is the dependency inversion principle.…The dependency inversion principle has two elements.…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.…There's a common theme to these two elements:…depend on abstractions.…The inversion part of this principle makes…a distinction between two views:…the "direct" dependency where a concrete class…depends on another concrete class…and an "inverted" dependency where a concrete class…depends only on an abstract interface.…
There may be many implementations of that interface.…In Python, a direct dependency on a class name…often shows up in object construction.…The name of the class is the dependency.…The other place it can show up is Python 3.5 type hints.…Python doesn't offer any first class support…for abstraction.…All Python classes are, in a way, concrete classes.…Because of duck typing though,…
To incorporate SOLID into your own development workflow, Steven Lott has prepared a series of lessons that break down the principles one by one, with real-world examples. Learn how to use these principles in the design process, and to test the strength of your code along the way. Steven uses Python to demonstrate the concepts, but they're useful for any object-oriented programming language.
- An overview of SOLID principles
- Segregating code into client-specific modules
- Testing code by substituting subtypes for base classes
- Keeping software open for extension but closed to modification
- Eliminating dependencies on details
- Assigning one responsibility to each class
- Using SOLID principles in the design process