What is the Difference Between Coupling and Cohesion?

🆚 Go to Comparative Table 🆚

Coupling and cohesion are two important concepts in software design that relate to the quality and maintainability of code. They are, however, distinct concepts with different implications for software design:

  • Cohesion refers to the degree of connection and relevance between the elements within a module, such as a class or a package. It is considered intra-module. High cohesion is desirable in software design because it indicates that all the elements within a module are related and serve a single purpose.
  • Coupling refers to the degree of interdependency between different modules, such as classes or packages. It is considered inter-module. Low coupling is generally preferred in software design because it means that the modules are more independent, making the code easier to maintain and modify.

In summary, cohesion focuses on the relationship within a module, while coupling focuses on the relationships between modules. High cohesion and low coupling are generally considered good characteristics in software design, as they lead to code that is easier to understand, maintain, and modify.

Comparative Table: Coupling vs Cohesion

Here is a table comparing the differences between coupling and cohesion:

Coupling Cohesion
Concept of inter-module relationships Concept of intra-module relationships
Indicates the relationships between modules Indicates the relationship within a module
Increasing coupling is avoided for software Increasing cohesion is good for software
Represents the independence among modules Represents the functional strength of modules
Created between two different modules Created within the same module
Low coupling is desirable High cohesion is desirable

Coupling refers to the degree of interdependence between software modules, while cohesion refers to the degree to which the elements within a module are related and serve a single purpose. High cohesion is associated with good software design, as it indicates that a module focuses on a single thing. On the other hand, low coupling is desirable because it indicates that the modules are as independent as possible. In summary, high cohesion and low coupling contribute to better software quality and maintainability.