Dependency Inversion (DI)

In DI, components declare their dependencies as interfaces, and a separate object (usually called a container or injector) is responsible for creating and wiring up the objects in the system, based on these interfaces.

The container is responsible for knowing how to create the objects and how to satisfy their dependencies, and it can be configured to use different implementations of these dependencies depending on the context in which the component is being used. This makes it easy to change the behavior of a component without having to change its code, simply by swapping out the dependencies that are injected into it.

DI is often used in conjunction with other design patterns and practices, such as the Single Responsability Principle (SRP) and Inversion of Control (IOC), to create modular, flexible, and maintainable software systems.


Backlinks