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
- Cohesion represents the degree to which a part of a code base forms a logically single atomic unit.
- Cohesion is an intra-module concept.
- Cohesion depicts the module’s relative functional strength.
- High cohesion is about keeping parts of a code base that are related to each other in a single place.
- Cohesion can be classified into the following classes: coincidental cohesion, logical cohesion, temporal cohesion, procedural cohesion, communication cohesion, sequential cohesion and functional cohesion.
- Cohesion is a kind of natural extension of data hiding for example, the class having all members visible with a package having default visibility.
- 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.
- Increase in cohesion is good for software.
- High cohesion gives the best software.
- 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
- Coupling represents the degree to which a single unit is independent from others (Coupling is the number of connections between two or more units.
- Coupling is an inter-Module concept.
- Coupling depicts the relative independence among modules.
- Low Coupling is about separating unrelated parts of the code base as much as possible.
- Coupling can be classified into the following classes: data coupling control coupling stamp coupling and common coupling.
- Making private fields, private methods and non public classes provides loose coupling.
- While designing, you need to strive for low coupling, that is, dependence between modules should be less.
- Increase in coupling is avoided for software.
- Loose coupling give the best software.
- 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.