Understanding Cohesion and Coupling in Software Design

What is Cohesion?

Cohesion indicates the relationships within a module. It reflects the module’s relative functional strength. Essentially, cohesion is the degree to which a component or module focuses on a single task.

Best Practices for Cohesion

When designing software, aim for high cohesion. A highly cohesive module concentrates on a single task with minimal interaction with other system modules. Cohesion naturally extends data hiding. For instance, a class with all members visible within a package demonstrates default visibility.

Key Takeaway: Cohesion is an Intra-Module concept.

What is Coupling?

Coupling indicates the relationships between modules. It shows the relative interdependence among modules. Coupling is the degree to which a component or module is connected to other modules.

Best Practices for Coupling

Strive for low coupling during the design phase. This means that the dependency between modules should be minimal. Loose coupling can be achieved by implementing private fields, private methods, and non-public classes.

Key Takeaway: Coupling is an Inter-Module concept.

Cohesion and Coupling: A Summary

  • Cohesion: Focuses on relationships within a module (Intra-Module).
  • Coupling: Focuses on relationships between modules (Inter-Module).
  • Goal: High cohesion and low coupling for better software design.