Inversion of Control (IoC) is a design principle where the control flow of a program is inverted: instead of your code calling a framework or library, the framework calls your code.

This is often referred o as the “Hollywood Principle”: don’t call us, we’ll call you.

Forms of IoC

IoC is a broad principle that manifests in several patterns, but the most common in application design is:

Why It Matters

IoC promotes loose coupling. Your components don’t need to know how to create their collaborators—they just declare what they need. This makes code:

  • Testable — You can substitute mock dependencies
  • Flexible — Swap implementations without changing consumers
  • Focused — Classes do one thing instead of managing their own dependencies

NOTE

IoC is the principle; Dependency Injection is the most common way to achieve it in application code.