Difference Between Cohesion and Coupling
Difference Between Cohesion and Coupling
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Cohesion
High cohesion is desirable as it leads to better maintainability, reusability, and understandability of the code
For example, a module that only handles file input/output operations would have high cohesion
used to measure the functional strength of a module systems having high cohesion will have strongly
connected elements such as instructions, groups of instructions, the definition of data, etc
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Module strength
This metric represents the associations of functions within the module.
When modules are arranged in order of higher module strength, the result is as follows:
Functional strength A collection of only functions that execute one certain process
Informational strength A collection of multiple independent functions that process specific data
Communicational strength A collection of multiple sequential functions, with internal passing of data
Procedural strength A collection of multiple sequential functions, without internal passing of data
In this type of cohesion, the elements inside a module work together to achieve one common goal.
The elements work in coordination with the main aim of staying focused on the task assigned.
Thus, they only perform the activities necessary for the assigned tasks.
For example, a module that calculates the area and perimeter of a rectangle would exhibit functional
cohesion.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Sequential Cohesion
Maintaining a sequence of activities makes our task much easier, right?
Sequential cohesion is present when the elements within a module are arranged in a specific order, and the
output of one element serves as the input for the next.
This helps in easy maintenance and provides good coupling due to a well-defined sequence.
An example of sequential cohesion can be seen in a module that reads data from a file, processes it, and
then writes the results to another file.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Communicational Cohesion
Communicational cohesion exists when the elements within a module are related through a common data
structure or shared data.
For instance, a module that retrieves customer information from a database and displays it on a webpage
would demonstrate communicational cohesion.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Procedural Cohesion
1. Procedural cohesion occurs when the elements within a module are grouped based on the steps required to
achieve a specific task.
2. An example of procedural cohesion can be observed in a module that handles user authentication, which
includes steps such as validating credentials, generating access tokens, and updating user activity logs.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Temporal Cohesion
Temporal cohesion is present when the elements within a module are related to a specific time frame or
event.
For example, a module that sends reminder notifications to users based on their scheduled appointments
would exhibit temporal cohesion.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Logical Cohesion
Logical cohesion occurs when the elements within a module are grouped based on a common logical
relationship.
An example of logical cohesion can be seen in a module that performs various mathematical operations,
such as addition, subtraction, multiplication, and division.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Cohesion
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Coupling
the degree to which the two modules are dependent on each other
Loosely coupled systems have modules that hardly depend on other modules and can focus better on their
assigned tasks
Low coupling is desirable as it leads to better modularity, flexibility, and testability of the code
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Module coupling
This metric represents associations with other modules.
When modules are arranged in order of weaker module coupling, the result is as follows:
Common coupling Externally declares and shares data including unnecessary Data
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Stamp Coupling
Stamp coupling refers to a situation where modules
communicate by passing a large data structure, but only
a small portion of that data is used.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Control Coupling
Control coupling occurs when one module controls
the behavior of another module by passing control
information.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
External Coupling
External coupling is a type of coupling where modules depend on external entities or systems outside of the
software system.
This type of coupling occurs when a module relies on external libraries, APIs, databases, or other software
components to perform its functions.
For example, let's say we have a module that needs to perform complex mathematical calculations.
Instead of implementing the mathematical algorithms from scratch, the module depends on an external
math library that provides pre-built functions for various mathematical operations.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Common Coupling
Common coupling happens when multiple modules depend on a shared global variable or data.
For instance, if multiple modules in a system access a global configuration file, they are tightly coupled
through the common data.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Content Coupling
This type of coupling occurs when one module directly accesses or modifies the content of another module.
For example, if module A directly reads or modifies a data structure defined in module B, it is considered
content coupling.
https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering