SE Modularity
SE Modularity
wh0 genera
for those who test andsubsequently support the software. generae rate codecode a
.
5.2 MODULARITY
There many definitions of the term
are
"module". They range from "a
subroutine" to "a module is an Ada module is a ROPTD
to "C++/ Java
package" "procedures and functions of PASCAL ande
to
Classes", to "Java packages" to "a module is a work assignment for an indivih
programmer" [FAIR2K]. All of these definitions are correct/ A
defined, manageable units with well defined interfaces modular system consist o'
of a modular system include: among the units. Desirable properie
S o f w a r eD e s i g n
207
dsle
Each mnod is a well delined subsystem that is
potentially useful in other
tions applica-
Each module has a single, well defined purpose
M
Jlas can be separately compiled and stored in a
library
use other modules
Modules can
fodules hould be easier to use than to build
Afadules
Mod should be simpler
outside than from the inside from the
Number of modules
thus, P
are strongly i n t e r c o n n e c t e d and
made
are
with low COupline Loosely coupled"
systems
W
coupling
are arenot.dependent on one another.
Software Engne
ed" .
208 coupled"
relatively
independent.
"Highly systems share a
modules
which are
For example, if modules
mako
of
shared great
between
modules.
at all; they are completely
1; they
are com.
global var
dependence
independent
i n t e r c o n n e c t i o n s
have no
Unovupled'modules aag
in Fig 5.5
Uncoupled: no dependencies
(a)
A good design will have low coupling. Thus, interfaces should be carefully
order to keep low value of coupling. specifed i
Coupling is measured by the number of interconnections between
modules. For exane-
ple, coupling increases as the number of calls
between modules increases, or the amounte
shared data increases. The
hypothesis that design with high coupling will have
is
Loose coupling, on the other
hand, minimizes the
more en
be achieved in the interdependence amongst modules. Tns
following way8:
Controlling the number of
Avoid passing undesired parameters passed amongst modules
data to calling module
Maintain parent/chilld
.Pass data, not the relationship between calling and called modules
control information
Fig. 5.6 demonstrates two alternative
Information System". design for editing a student cord in a "Stude
The r
first design demonstrates tight
dent name, student 28S
209
Edit student
Edit student
record
record
Student name
student ID Student
student address record EOOF Student ID Student
record EOF
course
Retrieve
Retrieve
student student
record
record
Types of coupling
Different types fcoupling are content, common, external, control, stamp and data. The strength
ling from
ofcoupling from lowest coupling (best) to highest coupling (worst) is given in Fig. 5.7.
Stamp coupling
Control coupling
External coupling
Common coupling
Given two procedures A and B, we can identify a number of ways in which they can be
coupled.
Data coupling A B
Ihe dependency between module A and B is said to be data coupled if their dependency is
n the fact they communicate by only passing of data. Other tham communicating through
modules are independent. A good strategy is to ensure that no module communi-
WO
cation
ntains "tramp data". In Fig, 5.6 above students name, address, course are examples ot
ran ensuring that modules
m a t are
unnecessarily communicated between modules. By
amunicate only necessary data, module dependency is minimized.
Stamp coupling Afrul
Slam
Samp coupling data structure is passed ro
occurs between module AandB when complete
one
modl OCCurs betwee
module5to anot the structure are usually
necessary 1n
Since not all data making up
er
pling typically involves
inve
210
the
modules,
stamp
couplin,
ofa
data
structure,
that
that npar
needs a
part
procedure
only s t r u c t u r e .
data
the complete
they communicat by
Control coupling
said to
be
control
coupledif
by
mcans
of that arec
flags that set by passing
one
f
Mod
odule A and
B
This
are
is
usually
accomplished
module.
modul
information.
dependent
the
e a c t e d upon by
modula
to other
rnal ttto the
. . .
to a particular
type of
hardware.
to th
or
ware being developed tools and
devices.
external
munication
to
Global:
A1
A2 Common data area and
A3
variable names
Variables:
V1
v2
Module X Module Z
Module Y
Fig. 5.8:
Example of common
coupling
Content coupling
pase
w*to D, eve
Dis supposed to be under the of another. In Fig. 5.9, module B branches
control of C.
Solare DA
Module B
Go To temp
Module DD
E
D
Go To temp
Temp
content coupling
Fig. 5.9: Example of
5.22 M o d u l e C o h e s i o n
module a r e functionally related.
which the elements of a feature ofthe solution
of thedegreeto is related to one
Cobesion is a measure
module implements
functionaity that
This is shown in Fig.
5.10. Cohesion
cohesive modules.
Astrongly interaction with other measure of the mutual off+city
and requires
little or n o
the module together. It is a
Module
strength
modules
within de
relations important
= Strength of Hence,
an
Cohesion module.
5.10:
Fig. within a module
coupling
interaction
the
the minimize
procedure
that
procedure that
i v e n aa
Given
G Y.
Types of cohesion shown in Fig.
in
5.11.
5 .11.
between
X and
cohesion
ar
a re
and
a nd ofcohesion
here are ofcohesion formsorms
of
ries
seven
opera
types or levels
we can
describe
various
Sguential wheaion
Commuicational coheaion
Prwvdural cohesion
Temporal cohesion
Logcal cohesion
of module cohesion
Fig.5.11: Types
ctional cohesion
functional task. This
18
very good reason for th.
Sequential cohesion
forms the input to Y. This is the reason for them to L.
X outputs s o m e data which to be contained
ed a
the same procedure.
For example, addition of marks of individual subjects into a specific fomat s
the result of the students.
calculate the GPA as input for preparing
A component is made of parts that need to communicate/exchange data for
ones
in a component for communico.Sou
fordifferent functional purposes. They are together
venience. For example calculate current and cumulative GPA uses the "student oro
as input.
Communicational cohesion
X and Y both operate on the same input data or contribute towards the same output data Thi
is okay, but we might consider making them separate procedures.
Procedural cohesion
X and Y are both structured in the same way. This is a poor reason for putting them in tha
same procedure. Thus, procedural cohesion occurs in modules whose instructions althou
accomplish different tasks yet have been combined because there is a specific order in whid
the tasks are to be completed. These types of modules are typically the result offirst lix
charting the solution to a program and then selecting a sequence of instructions tosere
module. Since these modules consist of instructions that acomplish several taskS
virtually unrelated these types of modules tend to be less maintainable. For
report module of an examination system includes the following "calculate student
student record, caleulate cumulative GPA, print cumulative GPA" is a case of procedural chesion
u
Temporal coheslon
X and Y both must perform around the same time. So, module exhibits tempor
i n thesame
when it contains tasks that are related
by the fact that all tasks
must be execut as set a ssetting
L o g i c a lc o h e s i o n
cally
perform logica similar operations. Therefore, logical cohesion OCcurs in modules
andininstructions that appear to be related because they fall into the same logical class
ht cons, Considerable duplication can exist in the logical strength level. For example,
of
fund
one
dataiitem in an input transaction may be a date. Separate code would be writ
than
that each such date is a valid date. A better way to construct a DATECHECK
ten tod call this module whenever a date check is necessary.
m o d u l
Coincidental c o h e s i o n
modules that contain instructions that have little or no relationship to one another.
ists in
e instead of creating two components, each of one part, only one component is made
w unrelated parts. For example, check validity and print is a single component with
two parts. Coincident cohesion is to be avoided as far as possible.
viewed.
If the sofbware is not properly modularized, a host of seemingly trivial enhancement or
of the project. Therefore, a good software design professes clean
changes will result into death
into modules and the arrangement of these modules in a neat
decomposition of a problem
hierarchy. Therefore, a software engineer must the modules with goal of high cohesion
design
and low coupling.
A good example of a system that has high cohesion and low coupling is the plug and
play' feature of the computer system. Various slots in the mother board of the system simply
facilitate to add or remove the various services/functionalities without affecting the entire
cohesive man-
system. This is because the add on components provide the services in highly
ner. Fig. 5.12 provides a graphical review of cohesion and coupling.
subordinate toshown
as
of these module
set of forn
those in which it is cross-linked tree structure in these heach module is
Since the
design progressed from
used. wne
design. The main bottom layer
design, chances of
the argument for this
design is that if
upwards, the methoa
validated sooner than arecoding high; but the
is we start le s00n
module soon after
coding a mouesign acan*
esign
module whose sub coded module can be ca
This method has modules have not yet been tested a
actly what functionality one terrible
weakness; we desigmed. cideer
a
module should need to use a lot of intu
provide.
SoftwareDesign
215
ig. Without a good idea about the operations needed at the higher layers, it is difficult to
n e what.operations the current layer should support |JAL098).
op-down to be effective, some bottom-up (mostly in the lowest design
levelo approach
approach is essential for the following reasons:
T0 permit common sub modules need
ear thebottom of the hierarchy, where the intuition is simpler, and the for
of modules at low levels
more numbers
#h pP testing is greater, because there are
than at high levels.
reuse of modules.
s e of pre-written library modules, in particular,