High cohesion, loose coupling

A module is cohesive if it provides functionality that logically belongs together. Modules are loosely coupled if you can change one without changing the other. Coupling defines a degree on which objects rely on each other.

With high cohesive modules changes in one of them should rarely require changes in other ones. Therefore if you find yourself in the opposite situation, it may be a sign that your modules are not cohesive.

Components should have loose coupling and high cohesion. It’s a fundamental principle in software development. Following it allows creating independent, reusable components with minimal dependencies on each other.

Loose cohesion, high coupling.

Loose cohesion, high coupling.

High cohesion, loose coupling

High cohesion, loose coupling.

It improves the following aspects of the module:

  • Maintainability and flexibility - loose coupling allows you to modify or replace individual components without affecting the entire system. This makes your code more adaptable to future changes and easier to maintain in the long run.
  • Scalability - components can be scaled independently. If one component experiences a surge in demand, you can scale it up without impacting other parts of the system.
  • Reusability - being focusing on a single task makes the module easier to reuse.
  • Complexity - by minimizing dependencies, it simplifies the overall system design. This makes it easier for developers to understand, debug, and test individual components.

References