0% found this document useful (0 votes)
34 views

Coupling Cohesion

The document discusses concepts related to software modularity including modules, cohesion, coupling, and hierarchical design. Modules consist of functions and associated data structures. High-level design identifies modules, control relationships, and interfaces. Good design displays high cohesion and low coupling between modules.

Uploaded by

Deneesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Coupling Cohesion

The document discusses concepts related to software modularity including modules, cohesion, coupling, and hierarchical design. Modules consist of functions and associated data structures. High-level design identifies modules, control relationships, and interfaces. Good design displays high cohesion and low coupling between modules.

Uploaded by

Deneesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Module

• A module consists of:


– several functions D1 ..
– associated data D2 ..
D3 ..
Data
structures. F1
F2
..
.. Functions
F3 ..
F4 ..
F5 ..
High-level
design d1 d2

• Identify: d3 d4
d1

- modules
- control relationships among modules
- interfaces among modules.
High-level design
• The outcome of high-level design:
–program structure, also called software
architecture.
Modularity
• In technical terms, modules should display:
– high cohesion
– low coupling.
Layering

Superior
Inferior
:Sourc
e

Bad
design
may look
like this…
Coupling: Degree of dependence among
components High coupling makes
modifying parts of the
system difficult, e.g.,
No dependencies Loosely coupled-some dependencies modifying a component
affects all the components
to which the component is
connected.

Highly coupled-many dependencies


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
interdependence or interaction between
the two modules.
Cohesion and Coupling
• A module having high cohesion and low
coupling:
– Called functionally independent of other
modules:
• A functionally independent module needs very little
help from other modules and therefore has minimal
interaction with other modules.
Measuring Functional Independence
• Unfortunately, there are no ways:
– to quantitatively measure the degree of cohesion
and coupling:
– At least classification of different kinds of cohesion and
coupling:
• will give us some idea regarding the degree of
cohesiveness of a module.
functional
sequential
Classification of communicational
Cohesiveness Degree of
procedural cohesion
temporal
logical
coincidental
Coincidental cohesion
• The module performs a set of tasks:
– which relate to each other very loosely, if at
all.
• That is, the module contains a random
collection of functions.
• functions have been put in the module out
of pure coincidence without any thought or
design.
Coincidental Cohesion - example
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.
• An example of logical cohesion:
– a set of print functions to generate an output
report arranged into a single module.
Logical Cohesion
module print{
void print-grades(student-file){ …}

void print-certificates(student-file){…}

void print-salary(teacher-file){…}
}
Temporal cohesion
• The module contains functions so that:
– all the functions must be executed in the same
time span.
• Example:
– The set of functions responsible for
• initialization,
• start-up, shut-down of some process, etc.
init() {

Check-memory(); Temporal
Check-Hard-disk(); Cohesion –
Example
Initialize-Ports();

Display-Login-Screen();

}
Procedural cohesion
• 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.
Communicational cohesion
• All functions of the module:
– Reference or update the same data structure,
• Example:
– The set of functions defined on an array or a
stack.
Communicational Cohesion
handle-Student- Data() {
Static Struct Student-data[10000];
Store-student-data();
Function A
Search-Student-data();
Function B

Print-all-students(); Function C

}; Communicational
Access same data
Sequential cohesion
• Elements of a module form different parts
of a sequence,
– output from one element of sort
the sequence is input to the
search
next.
display
– Example:
Functional cohesion
• 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 Determining
– If the sentence is compound, Cohesiveness
• 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
• Coupling indicates:
– how closely two modules interact or
how interdependent they are.
– The degree of coupling between two
modules depends on their interface
complexity.
Coupling
• There are no ways to precisely measure 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.
Classes of
coupling
data
stamp
control Degree of
coupling
common
content
Data coupling
• Two modules are data coupled,
– if they communicate via a parameter:
• an elementary data item,
• e.g an integer, a float, a character, etc.
– The data item should be problem related:
• not used for control purpose.
Stamp coupling
• Two modules are stamp coupled,
– if they communicate via a composite data item

• or an array or structure in C.
Control coupling
• Data from one module is used to direct
– order of instruction execution in another.
• Example of control coupling:
– a flag set in one module and tested in another
module.
Common Coupling

• Two modules are common coupled,


– if they share some global data.
Content coupling
• Content coupling exists between two modules:
– if they share code,
– e.g, branching from one module into another
module.
• The degree of coupling increases
– from data coupling to content coupling.
Hierarchical Design
• Control hierarchy represents:
– organization of modules.
– control hierarchy is also called program structure.
• Most common notation:
– a tree-like diagram called structure chart.
Software
Architecture
Good Hierachical Arrangement of
modules

• Essentially means:
– low fan-out
– abstraction
Morphology
Characteristics of Module Structure
• Depth:
– number of levels of control
• Width:
– overall span 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 in general encouraged.
Example
Module Structure
Fan out=2

Fan out=1
Fan in=1

Fan in=2
Fan out=0
Goodness of Design
• A design having modules:
– with high fan-out numbers is
not a good design.

– a module having high fan-out lacks cohesion.


Large Fan Out
• A module that invokes a large
number of other modules:
– likely to implement several different functions:
– not likely to perform a single cohesive function.

You might also like