Lecture 9 Cohesion and coupling
Lecture 9 Cohesion and coupling
encourage industry consultancy projects & nurture human values and life skills”.
Session by
[email protected]
Organization of this Lecture:
Lecture 9 Cohesion n
Coupling 2
Learning Outcome
Lecture 9 Cohesion n
Coupling 3
Characteristics of Good Design
n Modularization
(process of dividing a software system into multiple independent modules where
each module works independently)
Advantages of Modularization:
n Easy to understand the system.
n System maintenance is easy.
n A module can be used many times as their requirements. No need to
write it again and again.
n Component independence
n High cohesion M1 M2
n Low coupling
M3
Lecture 9 Cohesion n
Coupling
4
Coupling
Lecture 9 Cohesion n
Coupling
5
https://www.javatpoint.com/software-engineering-coupling-and-cohesion
Lecture 9 Cohesion n
Coupling 6
Data Coupling
Lecture 9 Cohesion n
Coupling
7 7
Stamp Coupling
n Example:
Passing structure variable in C or object in C++ language to a
module.
Lecture 9 Cohesion n
Coupling
8 8
Control Coupling
9 9
External Coupling
10
Common Coupling
11 11
Content Coupling
12 12
Cohesion
Lecture 9 Cohesion n
Coupling 13
https://www.javatpoint.com/software-engineering-coupling-and-cohesion
Lecture 9 Cohesion n
Coupling 14
Functional Cohesion
Function A part 2
Function A part 3
Sequential with complete, related functions
15 15
Sequential Cohesion
Function B
Function C
16 16
Communicational Cohesion
-- Functions performed on the same data or to
produce the same data.
When elements of module are grouped together, which are executed
sequentially and work on same data (information), it is called
communicational cohesion. Two elements operate on the same input data or
contribute towards the same output data.
n Examples:
n Update record in database and send it to the printer
n Fetch unrelated data at the same time(To minimize disk access)
Function A
Function B
Function C
17 17
Procedural Cohesion
--When elements of module are grouped together, which are
executed sequentially in order to perform a task, it is
called procedural cohesion.
Elements of procedural cohesion ensure the order of execution.
Actions are still weakly connected and unlikely to be reusable.
n Example:
1. Calculate student GPA,
n print student record, Function A
n calculate cumulative GPA,
n print cumulative GPA.... Function B
2. Write output record
n Read new input record Function C
n Pad input with spaces
n Return new record
Related by order of functions
18
Temporal Cohesion
n Elements are related by timing involved
n Elements are grouped by when they are processed.
Example:
n 1. An exception handler that Closes all open files,Creates an error log
Notifies user,Lots of different activities occur, all at same time.
n 2. A system initialization routine: this routine contains all of the code for
initializing all of the parts of the system. Lots of different activities occur, all at
init time.
Time t0
Time t0 + X
Time t0 + 2X
Related by time
19 19
Logical Cohesion
Function A
Function A’
Function A’’
Similar functions
20 20
Coincidental Cohesion
-- A module is said to have coincidental cohesion if it
performs a set of tasks that are associated with
each other very loosely, if at all.
It is unplanned and random cohesion.
n Accidental
n Worst form
Example : print next line and reverse the characters of a string in a
single component.
Function A
Function Function
B C
Function Function
D E
Parts unrelated
21 21
Coupling v/s Cohesion
Coupling Cohesion
Coupling is also called Inter-Module Binding. Cohesion is also called Intra-Module Binding.
Coupling shows the relationships between Cohesion shows the relationship within the
modules. module.
While creating, you should aim for low While creating you should aim for high
coupling, i.e., dependency among modules cohesion, i.e., a cohesive component/ module
should be less. focuses on a single function (i.e., single-
mindedness) with little interaction with other
modules of the system.
In coupling, modules are linked to the other In cohesion, the module focuses on a single
modules. thing.
Lecture 9 Cohesion n
Coupling 22
Summary
Lecture 9 Cohesion n
Coupling 23
References :
Lecture 9 Cohesion n
Coupling 24
Any Questions…??
Lecture 9 Cohesion n
Coupling 25
Lecture 9 Cohesion n
Coupling 26