Chapter 5 Cohesion Coupling
Chapter 5 Cohesion Coupling
Introduction
Design phase transforms SRS
document:
into a form easily implementable in some
programming language.
d1 d2
d3 d1 d4
What Is Good Software Design?
functional
sequential
communicational
Degree of
procedural cohesion
temporal
logical
coincidental
Coincidental
Cohesion
Coincidental cohesion
Module AAA{
Print-inventory();
Register-Student();
Issue-Book();
};
Logical cohesion
All elements of the module perform similar
operations:
e.g. error handling, data input, data output,
etc.
module print{
void print-grades(student-file){ …}
void print-certificates(student-file){…}
void print-salary(teacher-file){…}
}
Temporal cohesion
The module contains tasks that are related by the fact that all the
tasks must be executed in the same time span.
Initialize-Ports();
Display-Login-Screen();
}
Procedural cohesion
Function A
Function B
Function C
Procedural
Related by order of functions
32
32
Examples of Cohesion (Cont.)
Function A Function A
Function B Function B
Function C Function C
Communicational Sequential
Access same data Output of one is input to another
Function A part 1
Function A part 2
Function A part 3
Functional
Sequential with complete, related functions
33
33
Communicational cohesion
handle-Student- Data() {
Function A
Static Struct Student-data[10000];
Function B
Store-student-data(); Function C
Search-Student-data(); Communicational
Access same data
Print-all-students();
};
Sequential cohesion
display
Functional cohesion
2. Module-name: managing-book-lending
Functions: issue-book, return-book, query-book
Coupling
Coupling indicates:
➢how closely two modules interact or
how interdependent they are.
40
Classes of coupling
data
stamp
control Degree of
coupling
common
content
Data coupling
Depth:
number of levels of control
Fan-out:
a measure of the number of modules directly
controlled by given module.
Characteristics of Module
Structure
Fan-in:
indicates how many modules
directly invoke a given module.
High fan-in represents code reuse
and is generally encouraged.
Modularity
Neat arrangement of modules in a
hierarchy means:
1. low fan-out
Fan-out: a measure of the number of modules directly
controlled by given module.
2. abstraction
Module Structure
Fan out=2
Fan out=1
Fan in=2
Fan out=0
Goodness of Design