Skip to content

Latest commit

 

History

History

inversion-of-control

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Inversion of Control (IoC)

In software engineering, Inversion of Control (IoC) is a design pattern that allows the creation of loosely coupled code by changing the flow of control in the system. Instead of calling methods directly and tightly coupling objects to one another, IoC introduces a mediator that controls the flow of communication between objects. This mediator is usually called the IoC container, and it is responsible for instantiating, managing, and controlling the lifecycle of objects.

The IoC pattern is based on the Dependency Inversion Principle (DIP), which states that high-level modules should not depend on low-level modules, but instead, both should depend on abstractions. By using interfaces to define the interaction between modules, the system can be designed to be more flexible and easier to maintain.

There are two main types of IoC: Dependency Injection (DI) and Service Locator (SL). In DI, the dependencies of a class are injected into it by the IoC container at runtime, while in SL, the container is used to locate and retrieve the necessary dependencies.

IoC can bring several benefits to software systems, such as:

  • Reduced coupling between objects, which makes the system easier to maintain and test

  • Increased modularity, which allows for better code reuse and scalability

  • Improved separation of concerns, as objects no longer need to know about the creation and management of their dependencies

  • Better flexibility and configurability, as the system can be easily modified by changing the IoC container configuration