When two layers or components or classes (in context of OOP paradigm) interact with each other or uses some other component, they are coupled in certain ways. Also, known as "dependencies".
The lesser a component know about its dependencies the looser coupled they are.
The information they need to know in order to use them, such as creating a new instance.
One of the biggest advantage is maintenance. The looser coupled code is, a lot easier to maintain.
Some of the ways we can promote loose coupling in Java:
- Passing Interfaces instead of concrete classes.
- Look for the use of new keyword for creating a new object, and using factory method or Dependency injection.
- Creating Rest/Messaging/Event interfaces to interact instead of using direct (like maven) dependencies of Jar files.
No comments:
Post a Comment