Академический Документы
Профессиональный Документы
Культура Документы
An early attempt to describe modules is by Stevens, Mayers and Constantine, who defined a module
as:
“ A set of one or more contiguous program statements having a name by which other parts of the
system can invoke it, and preferably having its own distinct set of variable names”.
In other words, a module consists of a single block of code that can be invoked in the way that a
procedure, function, or method is invoked.
Yourdon and Constantine gave a broader definition:
“A module is a lexically contiguous sequence of program statements, bounded by boundary elements,
having an aggregate identifier” [2].
Number of modules
Fig 1: Modularity and software cost
We modularize a design (and the resulting program) so that development can be more easily
planned; software increments can be defined and delivered; changes can be more easily
accommodated; testing and debugging can be conducted more efficiently and long term maintenance
can be conducted without serious side effects. [1]
1
Coupling
Cohesion [1]
FUNCTIONAL INDEPENDECE:
Functional independence is achieved by developing modules with “single-minded” function and an
“inversion” to excessive interaction with other modules. In other words, we want to design software
so that each module addresses a specific subfunction of requirements and has a simple interface when
viewed from other parts of the program structure.
Software with effective modularity, that is, independent modules, is easier to develop because
function may be compartmentalized and interfaces are simplified. Independent modules are easier to
maintain (and test) because secondary effects caused by design or code modification are limited, error
propagation is reduced, and reusable modules are possible. In short, functional independence is a key
to good design, and design is the key to software quality.
Independence is assessed using two qualitative criteria: cohesion, the degree of interaction within a
module, and coupling, the degree of interaction between two modules. [1]
COHESION:
Cohesion is the measure of the strength of functional relative ness of elements within a module; that
is putting strongly associated things in the same module. Cohesion implies that a component or class
encapsulates only attributes and operations that are closely related to one another and to the class or
component itself.
LEVELS OF COHESION:
In general, the higher the level of cohesion, the easier the component is to implement, test, and
maintain. We can develop a scale of cohesion, ranging from best cohesion to worst cohesion, as
shown below.
1. Functional cohesion
2. Sequential cohesion (Good)
3. Communicational Cohesion
4. Procedural cohesion
5. Temporal cohesion
6. Logical cohesion
7. Coincidental cohesion (Bad)
Fig 2: Levels of cohesion [2]
FUNCTIONAL COHESION:
Exhibited primarily by operations, this level of cohesion occurs when a module performs one and
only one computation and then returns a result. [1]
Advantages:
A module with functional cohesion often can be reused because the one action that it
performs often needs to be performed in other products.
Maintenance is easier to perform on a module with functional cohesion.
Functional cohesion leads to fault isolation.
2
Because a module with functional cohesion performs only one action, such a module
generally is easier to understand than a module with lower cohesion. This ease in
understanding also simplifies the maintenance.
When any change is made, the chance of that change affecting other modules is slight,
especially if the coupling between modules is low.
Functional cohesion also is valuable when a product has to be extended. [2]
Examples:
Examples of such modules are get temperature of furnace; compute orbital of electron; write
to diskette; and calculate sales commission. [2]
Definition of
sales region table
COMMUNICATIONAL COHESION:
All operations that access the same data are defined within one class. A module has
communicational cohesion if it performs a series of actions related by the sequence of steps to be
3
followed by the product and if all the actions are performed on the same data. These modules are
quite maintainable but there are problems, as the modules cannot be reused. The solution is to break
such modules into separate modules, each performing one action.
Examples:
Module Determine Customer Details
o Uses Customer Account Number
o Find Customer Name
o Find Customer Loan Balance
o Return Customer Name, Customer Loan Balance
End Module
Update record in database and write it to the audit trial.
Calculate new trajectory and send it to the printer. [1], [2]
PROCEDURAL COHESION:
In procedural cohesion, components or operations are grouped in a manner that allows one to be
invoked immediately after the preceding one was invoked, even when there is no data passed
between them. The disadvantage is that the actions are weakly connected, and the module is unlikely
to be reusable in another product. The solution is to break up a module with procedural cohesion into
separate modules, each performing one action.
Examples:
In Average module, Summation is followed by Average and then Display.
A module with procedural cohesion is read part number from database and update repair
record on maintenance file. [1], [2]
TEMPORAL COHESION:
Temporally cohesive module is one whose elements are unrelated to one another except that they are
carried out at a particular time. That is a module has temporal cohesion when it performs a series of
actions related in time. The actions of such a module are related weakly to one another but more
strongly to actions in other modules. In addition, a module with temporal cohesion is unlikely to be
reusable in a different product. [2]
Examples:
An example of a module having temporal cohesion is one named open old master file, new
master file, transaction file, and print file, initialize sales region table, read first transaction
record, and first old master file record. [2]
COINCIDENTAL COHESION:
A module has coincidental cohesion if it performs multiple, completely unrelated actions. [2]
Disadvantages:
Modules with coincidental cohesion degrade the maintainability of the product, both
corrective maintenance and enhancement.
These modules are not reusable. [2]
Example:
An example of a module with coincidental cohesion is a module named print next line, reverse the
string of characters comprising the second argument, add 7 to the fifth argument, convert the fourth
argument to floating point. [2]
COUPLING:
Coupling is a qualitative measure of the degree to which classes are connected to one another. As
classes (and components) become more interdependent, coupling increases. In general, it is desirable
to reduce the amount of coupling as much as possible, since connections between software
components inhibit ease of development, modification, or reuse. Eliminating unnecessary
relationships and reducing the number of necessary relationships can minimize coupling. [1]
Reasons for reducing coupling:
When there are fewer connections between two modules, there is less chance for ripple effect.
We want to be able to change a module with minimum risk of change in other modules – a
change should affect as fewer modules as possible.
In maintaining a module, we should not worry about the internal details of other modules –
we want the system to be as simple as possible.
5
LEVELS OF COUPLING:
A number of levels of coupling can be distinguished, as shown in fig 5.
1. Data coupling (Good)
2. Stamp coupling
3. Control coupling
4. Common coupling
5. Content coupling (Bad)
Fig 5: Levels of coupling [2]
DATA COUPLING:
Data coupling occurs when operations pass long strings of data arguments. In other words, two
modules are data coupled if all arguments are homogeneous data items. That is, every argument is
either a simple argument or a data structure in which all elements are used by the called module.
Data coupling is a desirable goal. If two modules are data coupled, then maintenance is easier,
because a change to one module is less likely to cause a regression fault in the other. [2]
Examples:
Examples include display time of arrival (flight number), compute product (first number, second
number, result), and determine job with highest priority (job queue). [2]
STAMP COUPLING:
Two modules are stamp coupled if a data structure is passes as an argument, but the called module
operates on only some of the individual components of that data structure. [2]
Examples:
Examples include calculate withholding (employee record) and check altitude (pointer to position
record). [2]
CONTROL COUPLING:
Two modules are controlled coupled if one passes an element of control to the other module.; that is,
one module explicitly controls the logic of the other.
If module q passes information back to module p and p decides what action to take as a consequence
of receiving that information, then q is passing data. But if q not only passes back information but
also informs module p as what action p must take, then control coupling is present.
Disadvantage:
The major difficulty that arises s a consequence of control coupling is that the two modules are
independent; module q, the called module, has to be aware of the internal structure and logic of
module p. As a result, the possibility of reuse is reduced. [2]
Examples:
Control is passed when a function code is passed to a module with logical cohesion. Another
example of control coupling is when a control switch is passed as an argument. [2]
COMMON COUPLING:
Two modules are common coupled if both have access to the same global data. [2]
Disadvantages:
This form of coupling is undesirable for a number of reasons.
6
It contradicts the spirit of structured programming in that the resulting code is virtually
unreadable.
Modules can have side effects that affect their readability.
If a maintenance change is made in one module to the declaration of a global variable, then
every module that can access tat global variable as to be changed. Furthermore, all changes
must be consistent.
A common-coupled module is difficult to reuse because the identical list of global variables
has to be supplied each time the module is reused.
As a consequence of common coupling, a module may be exposed to more data than it needs.
This defeats any attempts to control data access and ultimately may lead to computer crime.[2
Examples:
An example is shown in the following figure. Instead of communicating with one another by passing
arguments, modules cca and ccb can access and change the value of global variable. [2]
cca ccb
Global variable
***************************
References:
1. Software engineering; A practitioner’s approach, sixth edition, by Roger S. Pressman
2. Object-oriented and classical software engineering, fifth edition, by Stephen R. Schach