It’s possible that in technical meetings you listened these terms, at the beginning they sound a little confusing and complex but the true is that they are just principles in Software Engineering.
Inversion of Control (IoC) is a concept to delegate the full responsibility to manage objects to some container or framework. Using this concept allows you more flexibility in your code as switching between implementations, decoupling your code and letting your code easy to be tested by the simple reason that the components will be isolated.
And one way to achieve it is using Dependency Injection (DI)
Dependency Injection is a pattern where the main idea is to have a separate object responsible to populates a dependency for another object.
Looking at an example below related to Books and Sections, if we don’t use DI and we need to create a book object, in this case we need to define a specific implementation for “sections” inside the constructor, and we create an unnecessary coupling:
public class Book {
private List<Section> sections;
public Book() {
sections = new ArrayList<>();
}
}
On the other hand, if we use DI we can delegate the responsibility to create “sections” to other object, container or framework, and this lets your code more flexible.
public class Book {
private List<Section> sections;
public Book(List<Section> sections) {
this.sections = sections;
}
}
And using the Spring Framework and just using an “annotation” allows us to delegate the responsibility to another object that could has many implementations and letting easy to interchange between them:
public class Book {
@Autowired
private List<Section> sections;
}
I hope it allows you to understand better!
References:
https://www.baeldung.com/inversion-control-and-dependency-injection-in-spring