[go: up one dir, main page]

0% found this document useful (0 votes)
52 views19 pages

Difference Between Cohesion and Coupling

Uploaded by

zaw paing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views19 pages

Difference Between Cohesion and Coupling

Uploaded by

zaw paing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Difference between Cohesion and Coupling

Difference between Cohesion and Coupling


 cohesion deals with the interconnection between the elements of the same module

 coupling deals with the interdependence between software modules

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

 high cohesion is preferred

https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Module strength
 This metric represents the associations of functions within the module.

 A better module has a higher strength.

 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

Temporal strength A collection of multiple functions executed at a specific Timing

Logical strength A collection of multiple functions selected by parameters

Coincidental strength A collection of meaningless functions partitioned by size and others

Chapter 4 Development Technology


Functional Cohesion
 This type of cohesion occurs when the elements within a module perform similar functions.

 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?

 That’s exactly what sequential cohesion does.

 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

 It measures the strength of relationships between modules

 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

 For example, if a change in one module


requires making modifications in multiple
other modules, it indicates high coupling

https://unstop.com/blog/difference-between-cohesion-and-coupling-in-software-engineering
Module coupling
 This metric represents associations with other modules.

 A better module has a weaker coupling.

 When modules are arranged in order of weaker module coupling, the result is as follows:

Data coupling Passes only parameters that do not affect control

Stamp coupling Passes the data structure itself

Control coupling Passes parameters that affect control

External coupling Externally declares and shares only necessary data

Common coupling Externally declares and shares data including unnecessary Data

Content coupling Directly looks up data in other modules

Chapter 4 Development Technology


Data Coupling
 Data coupling is a desirable level of coupling where
modules communicate by passing only the necessary data
between them.

 The data shared can be of integer or float data types.

 In this case, modules are independent of each other's


internal structure.

 For instance, if module A sends specific data to module B


without any knowledge of how module B processes it, it
demonstrates data coupling.

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.

 For example, if module A passes a complex object to


module B, but module B only needs a few fields from
that object, it is considered stamp coupling.

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.

 An example of this is when module A calls a function


in module B and passes a control flag or parameter to
determine the execution flow.

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.

 In this type of coupling, the interacting modules share code.

 Here one module depends on the implementation of the other 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

You might also like