Asst - Prof. Sunitha E.V: Department of Information Technology Tist
Asst - Prof. Sunitha E.V: Department of Information Technology Tist
V
Department of Information Technology
TIST
In
technical terms, modules
should display:
◦ High cohesion
◦ Low coupling.
We shall next discuss:
◦ cohesion and coupling.
Cohesion is a measure of:
◦ functional strength of a module.
◦ A cohesive module performs a
single task or function.
Coupling between two modules:
◦ A measure of the degree of the
interdependence or interaction
between the two modules.
Amodule having high
cohesion and low coupling:
◦ functionally independent of
other modules:
A functionally independent
module has minimal interaction
with other modules.
Better understandability and
good design:
Complexity of design is reduced,
understood in isolation:
◦ Modules are independent
Functional independence reduces
error propagation.
◦ Degree of interaction between
modules is low.
◦ An error existing in one module does
not directly affect other modules.
Reuse of modules is possible.
A functionally independent module:
◦ Can be easily taken out and reused in
a different program.
Each module does some well-defined
and precise function
The interfaces of a module with other
modules is simple and minimal.
Unfortunately, there are no ways:
◦ To quantitatively measure the
degree of cohesion and coupling.
◦ Classification of different kinds of
cohesion and coupling:
Can give us some idea regarding
the degree of cohesiveness of a
module.
Classification is often subjective:
◦ Yet gives us some idea about
cohesiveness of a module.
By examining the type of
cohesion exhibited by a module:
◦ We can roughly tell whether it
displays high cohesion or low
cohesion.
functional
sequential
communicational Degree of
procedural cohesion
temporal
logical
coincidental
The module performs a set of tasks:
◦ Which relate to each other very
loosely, if at all.
The module contains a random
collection of functions.
Functions have been put in the module
out of pure coincidence without any
thought or design.
All elements of the module
perform similar operations:
◦ e.g. error handling, data input,
data output, etc.
An example of logical cohesion:
◦ A set of print functions to
generate an output report
arranged into a single module.
The module contains tasks that are
related by the fact:
◦ All the tasks must be executed in the
same time span.
Example:
◦ The set of functions responsible for
initialization,
start-up, shut-down of some process,
etc.
The set of functions of the module:
◦ All part of a procedure (algorithm)
◦ Certain sequence of steps have to be
carried out in a certain order for
achieving an objective,
e.g. the algorithm for decoding a message.
All functions of the module:
◦ Reference or update the same data
structure,
Example:
◦ The set of functions defined on an
array or a stack.
Elements of a module form
different parts of a sequence,
◦ Output from one element of the
sequence is input to the next.
◦ Example:
sort
search
display
Different elements of a module
cooperate:
◦ To achieve a single function,
◦ e.g. managing an employee's pay-roll.
When a module displays functional
cohesion,
◦ We can describe the function using a
single sentence.
Write down a sentence to describe
the function of the module
◦ If the sentence is compound,
It has a sequential or communicational
cohesion.
◦ If it has words like “first”, “next”,
“after”, “then”, etc.
It has sequential or temporal cohesion.
◦ If it has words like initialize,
It probably has temporal cohesion.
Coupling indicates:
◦ How closely two modules
interact or how interdependent
they are.
◦ The degree of coupling
between two modules depends
on their interface complexity.
There are no ways to precisely
determine coupling between two
modules:
◦ Classification of different types of
coupling will help us to approximately
estimate the degree of coupling between
two modules.
Five types of coupling can exist
between any two modules.
data
stamp
control Degree of
coupling
common
content
Two modules are data coupled,
◦ If they communicate via a parameter:
an elementary data item,
e.g an integer, a float, a character,
etc.