- What is dependency?
- Dependency Inversion Principle (SOLID)
- Inversion of Control
- Dependency Injection
Let’s get started!
There are a lot of well developed modules that makes one or more jobs very efficiently. In order to build up software with ease this modules have to be used. This is the part where dependency comes into play. Dependency is the modules/components that are our project uses and needs in order to work. This dependency could be used framework, third party libraries, database, file system, built in libraries, external services etc.
Dependency Inversion Principle
As in all software development processes, in order to achieve standards and increase quality, there are certain principles in dependency processes. One of them is called Dependency Inversion Principle which is the last one of the famous SOLID principles. Dependency Inversion Principle has two rules.
- High-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.
In short, this principle reduces the cost of the maintenance for software by minimizing ripple effect. If there need to be a change in a method or class, that change should effect minimal functionality as possible. Otherwise, there should be more regression tests in order to validate robustness of software. Also, as opposed to the code that well-proven and long-lived in the production without any issue, the updated code requires time to be accepted as robust as before.
Inversion of Control (IOC)
The aim of the IOC design pattern (some may refer to it as design principle) to help in designing loosely coupled classes in order to increase testability and maintainability.
Dependency Injection (DI)
There are three types of injecting dependencies:
- Constructor injection
- Setter/Getter injection
- Interface injection
Spring uses constructor injection and setter/getter injection.