Coupling and Cohesion
Coupling and Cohesion
Cohesion:-
Cohesion is a natural extension of the information hiding concept. A cohesive module performs a
single task within a software procedure, requiring little interaction with procedures being
performed in other parts of a program. Cohesion may be represented as a "spectrum." We always
strive for high cohesion, although the mid-range of the spectrum is often acceptable. The scale
for cohesion is nonlinear.
Coincidental cohesion:-
This occurs when there is no relationship among elements of a module. They can occur if an
existing program modularized by chopping it into pieces and making differ piece of modules i.e.
it performs a set of tasks that are related to each other very loosely. The modules contain a
random collection of function.
Logical cohesion:-
A module having logical cohesion if there are some logical relationship between elements of a
modules i.e. elements of a module performs the operation.
Temporal cohesion:-
It is same as logical cohesion except that the element must be executed in same time. Set of
function responsible for initialization, startup, the shutdown of the same process. It is higher than
logical cohesion since all elements are executed together. This avoids the problem of passing the
flag.
Communicational cohesion:-
A module is said to have Communicational cohesion if all function of module refers to an update
the same data structure.
Sequential cohesion:-
A module is said to have sequential cohesion if element module from different parts of the
sequence. When the output from one element of the sequence is input to the next element of a
sequence. A sequence bounded module may contain several functions or part of different
functions.
Functional cohesion:-
It is the strongest cohesion in a functional bound module, all elements of the module are related
to performing a single function. By function we not mean simply mathematical function but also
these modules which have single goal function like computing square root and sort array are a
clear example of functionality cohesion modules.
Coupling:- Coupling is a measure that defines the level of inter-dependability among modules of
a program. It tells at what level the modules interfere and interact with each other. The lower the
coupling, the better the program.
Definition:- Coupling represents the relationships between modules. Increasing in cohesion is good for
software. Increasing in coupling is avoided for software. Cohesion represents the functional strength of
modules. Coupling represents the independence among modules.
There are five levels of coupling are:-
• Content coupling - When a module can directly access or modify or refer to the content of
another module, it is called content level coupling.
• Common coupling- When multiple modules have read and write access to some global data, it
is called common or global coupling.
• Control coupling- Two modules are called control-coupled if one of them decides the function
of the other module or changes its flow of execution.
• External Coupling: This type of coupling occurs when an external imposed data format and
communication protocol are shared by two modules. External Coupling is generally related to the
communication to external devices.
• Message Coupling: This type of coupling can be achieved by the state decentralization. It is
the loosest type of coupling, in which the component communication is performed through
message passing.
• Stamp coupling- When multiple modules share common data structure and work on different
part of it, it is called stamp coupling.
• Data coupling- Data coupling is when two modules interact with each other by means of
passing data (as parameter). If a module passes data structure as parameter, then the receiving
module should use all its components.