Inversion of Control (IoC) is a design concept where the control flow of a program is inverted compared to traditional procedural programming. Instead of your code calling library code, the framework calls your code.
Core Concept
In traditional programming, your code controls when and how libraries are used:
Your Code → calls → Library Code
With IoC, the framework controls the flow and calls your code:
Framework → calls → Your Code
Relationship to Dependency Injection
Dependency Injection (DI) is a specific implementation of Inversion of Control. While IoC is the broader concept of framework-controlled flow, DI specifically addresses how dependencies are provided to objects.
Key Distinction:
- IoC: The principle of inverting control flow
- DI: A pattern for implementing IoC by injecting dependencies rather than creating them
All DI is IoC, but not all IoC is DI. Other IoC examples include event-driven programming, template method pattern, and frameworks like React or Angular.
Resources
- Inversion of Control vs Dependency Injection - Clear explanation of the distinction
Related Concepts
- Design Concepts - Theoretical foundations
- SOLID Principles - Dependency Inversion Principle is related but distinct
- Design Patterns - Template Method is an IoC pattern
- Good Software Practices
See Also
- Architectural Patterns - Framework-level applications of IoC