Coupling in Java
These components are tightly coupled with each other. Without affecting any component, we can’t modify any component. This type of programming is not recommended. Whenever we are developing the components compulsory, we should maintain very less dependency between the components, i.e. we have to maintain loosely coupling.
The main advantages of loosely coupling are:
- It improves maintainability.
- It makes enhancements easy.
- It produces reusability.
There are two types of coupling
1. Loose Coupling
When two classes, modules, or components have low dependencies on each other, it is called loose coupling in Java. Loose coupling in Java means that the classes are independent of each other.
The loose coupling in Java has the edge over tight coupling as it reduces code maintenance and efforts. A change in one class does not require changes in the other class, and two classes can work independently.
2. Tight Coupling
When two classes are highly dependent on each other, it is called tight coupling. It occurs when a class takes too many responsibilities or where a change in one class requires changes in the other class.