---
title: "Dependency Inversion Principle"
section: "concepts"
type: "concept"
created: "2026-08-25"
updated: "2026-08-25"
tags: ["principle"]
canonical: "https://pyweb.dev/wiki/dependency-inversion-principle"
---
# Dependency Inversion Principle

A design principle that enables [clean architecture](/wiki/clean-architecture)'s [dependency rule](/wiki/dependency-rule) to work in practice by using dynamic polymorphism to create source code dependencies that oppose the flow of control. This allows necessary communication across architectural boundaries while maintaining inward-pointing dependencies.

## Mechanism

When control must flow outward (violating the dependency rule):
1. **Inner layer defines interface** — specifies the contract it needs
2. **Outer layer implements interface** — provides concrete implementation  
3. **Source dependency points inward** — satisfies the dependency rule
4. **Control flows outward** — achieves necessary functionality

## Practical Application

**Example**: Use case needs to call presenter
- Use case calls interface (Use Case Output Port) in its own layer
- Presenter implements that interface in the outer layer
- Source code dependency: Presenter → Use Case Output Port (inward)
- Control flow: Use Case → Presenter (outward)

## Role in Clean Architecture

The dependency inversion principle is the key mechanism that allows [clean architecture](/wiki/clean-architecture) to maintain the [dependency rule](/wiki/dependency-rule) while enabling all necessary communication between layers. Without this principle, the architectural constraints would be impossible to satisfy in practice.

 [[source: uncle-bob-clean-architecture-2012]](/wiki/raw/articles/uncle-bob-clean-architecture-2012)

---

## Agent Navigation

cluster: person (170 pages) | betweenness: 50.8

### References (outbound)
- [Clean Architecture](https://pyweb.dev/wiki/clean-architecture.md)

### Referenced by (inbound)
- [Clean Architecture](https://pyweb.dev/wiki/clean-architecture.md)
- [Dependency Rule](https://pyweb.dev/wiki/dependency-rule.md)
- [Model Provider Abstraction](https://pyweb.dev/wiki/model-provider-abstraction.md)

### Evidence (verified primary sources)
- [uncle-bob-clean-architecture-2012](https://pyweb.dev/wiki/raw/articles/uncle-bob-clean-architecture-2012.md) | origin: https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html | ingested: 2026-08-25 | sha256: b99ae450b5981dbee264aec42701b920ce96ccedea01d03243ea48c414442379

### Machine endpoints
- Knowledge graph: https://pyweb.dev/api/graph.json
- Graph analysis: https://pyweb.dev/api/graph-analysis.json
- Context index: https://pyweb.dev/llms.txt
