10 Difference Between Coupling And Cohesion In Software Engineering (With Examples)

SHARE

What Is Cohesion In Software Engineering?

In software engineering, cohesion represents the degree to which a part of a code base forms a logically single, atomic unit. It also can be described as the degree to which the elements of a module belong together or the number of connections inside some code unit. If the number is low, then boundaries for the unit are probably chosen badly, the code inside the unit is not logically related.

The different classes of cohesion a module may possess include:

  • Coincidental Cohesion
  • Procedural Cohesion
  • Sequential Cohesion
  • Functional Cohesion
  • Communication Cohesion
  • Temporal Cohesion
  • Logical Cohesion

What You Need To Know About Cohesion

  1. Cohesion represents the degree to which a part of a code base forms a logically single atomic unit.
  2. Cohesion is an intra-module concept.
  3. Cohesion depicts the module’s relative functional strength.
  4. High cohesion is about keeping parts of a code base that are related to each other in a single place.
  5. Cohesion can be classified into the following classes: coincidental cohesion, logical cohesion, temporal cohesion, procedural cohesion, communication cohesion, sequential cohesion and functional cohesion.
  6. Cohesion is a kind of natural extension of data hiding for example, the class having all members visible with a package having default visibility.
  7. While designing, you need to strive for high cohesion, that is, focus on a single task with little interaction with other modules of the system.
  8. Increase in cohesion is good for software.
  9. High cohesion gives the best software.
  10. It is possible to create fully cohesive code without introducing unnecessary coupling.

What Is Coupling In Software Engineering?

In software engineering, coupling is the degree of interdependence between software modules. Two modules that are tightly coupled are strongly dependent on each other. On the other hand, two modules that are loosely coupled are not dependent on each other. They are henceforth referred to as uncoupled modules. Uncoupled modules have no interdependence at all within them.

There are various types of module coupling, and they include:

  • No direct coupling
  • Data coupling
  • Stamp coupling
  • Control coupling
  • Common coupling
  • Content coupling
  • External coupling

What You Need To Know About Coupling

  1. Coupling represents the degree to which a single unit is independent from others (Coupling is the number of connections between two or more units.
  2. Coupling is an inter-Module concept.
  3. Coupling depicts the relative independence among modules.
  4. Low Coupling is about separating unrelated parts of the code base as much as possible.
  5. Coupling can be classified into the following classes: data coupling control coupling stamp coupling and common coupling.
  6. Making private fields, private methods and non public classes provides loose coupling.
  7. While designing, you need to strive for low coupling, that is, dependence between modules should be less.
  8. Increase in coupling is avoided for software.
  9. Loose coupling give the best software.
  10. It is impossible to achieve full decoupling without damaging cohesion.

Cohesion And Coupling Diagram

Also Read: Difference Between Spiral Model And Prototype Model In Software Engineering

Difference Between Cohesion And Coupling In Tabular Form

BASIS OF COMPARISON COHESION COUPLING
Description Cohesion represents the degree to which a part of a code base forms a logically single atomic unit.   Coupling represents the degree to which a single unit is independent from others (Coupling is the number of connections between two or more units.  
Concept It is an intra-module concept.   It is an inter-Module concept.  
What does It Depicts? It depicts the module’s relative functional strength.   It depicts the relative independence among modules.  
What does It Entail? High cohesion is about keeping parts of a code base that are related to each other in a single place.   Low Coupling is about separating unrelated parts of the code base as much as possible.  
Types/Classes Coincidental cohesion Logical cohesion Temporal Cohesion  Procedural Cohesion Communication Cohesion Sequential Cohesion Functional Cohesion.   Data coupling Control coupling Stamp coupling Common coupling.  
Manipulation   Cohesion is a kind of natural extension of data hiding for example, the class having all members visible with a package having default visibility.   Making private fields, private methods and non public classes provides loose coupling.  
 Designing While designing, you need to strive for high cohesion, that is, focus on a single task with little interaction with other modules of the system.   While designing, you need to strive for low coupling, that is, dependence between modules should be less.  
Increase In Coupling Vs Cohesion Increase in cohesion is good for software.   Increase in coupling is avoided for software.  
How Best Software Is Achieved High cohesion gives the best software.   Loose coupling give the best software.  
Possibility It is possible to create fully cohesive code without introducing unnecessary coupling.     It is impossible to achieve full decoupling without damaging cohesion.  

Comments are closed.