Inversion of Control
Inversion of Control shifts control of program flow from application code to the framework/container, with the framework calling back into application code.
Purpose
Invert control flow from the called library to the calling framework, achieving loose coupling and extensible architecture.
Mechanism
Traditionally, the application calls the library. With IoC, the framework controls the flow and calls back into the application at the right points (Hollywood Principle). DI is one form of IoC. Event loops, template methods, and callbacks are all manifestations of IoC.
Use cases
- Framework design
- Loose coupling
- Event-driven