Inversion of control

Computer Science

inversion of control (IoC) is a programming technique, expressed here in terms of object-oriented programming, in which object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis.
Let's say you have some sort of "repository" class, and that repository is responsible for handing data to you from a data source. The repository could establish a connection to the data source by itself. But what if it allowed you to pass in a connection to the data source through the repository's constructor? By allowing the caller to provide the connection, you have decoupled the data source connection dependency from the repository class, allowing any data source to work with the repository, not just the one that the repository specifies. You have inverted control by handing the responsibility of creating the connection from the repository class to the caller. Martin Fowler suggests using the term "Dependency Injection" to describe this type of Inversion of Control, since Inversion of Control as a concept can be applied more broadly than just injecting dependencies in a constructor method. credit: https://softwareengineering.stackexchange.com/questions/205681/why-is-inversion-of-control-named-that-way