What is the dependency inversion principle and why is it important?
Inversion of control (IoC) is a design pattern where an object gets handed its dependency by an outside framework, rather than asking a framework for its dependency.
Pseudocode example using traditional lookup:
class Service {
Database database;
init() {
database = FrameworkSingleton.getService("database");
}
}
Similar code using IoC:
class Service {
Database database;
init(database) {
this.database = database;
}
}
The benefits of IoC are: