You are on page 1of 25

Coupling & Cohesion

Modularization
is a process of breaking software into multiple small modules, where
each module works independently. The main advantage of
modularization is that it is easy to understand the software, it becomes
reusable, and can be tested easily.
Coupling
it is the inter-dependency or degree of relationship between multiple
modules/packages/components.

- is also called Inter-Module Binding

Multiple modules/packages/components that are highly coupled are strongly


dependent on each other
.
Multiple modules/packages/components that are loosely coupled are not or
somehow dependent on each other.

Uncoupled modules have no interdependence at all within them.


No Direct Coupling:
There is no direct coupling
between M1 and M2.

In this case, modules are


subordinates to different modules.
Data Coupling

When data of one module is


passed to another module,
this is called data coupling.
Stamp coupling
Stamp coupling happens when the
modules of a program communicate
among themselves using a composite
data structure.

The composite data structures can be


arrays, structures, unions, etc.

The parameters that are passed


between the modules through a
composite data structure may or not be
fully used by the receiving module
Control Coupling
If two modules are communicating
with each other by passing the
information about the control flow,
then the two modules are known to
be in control coupling.

- one module is working on the


functions of the modules or takes
decision on changing the flow of
execution and the second module
transfers the control information to
the first module and hence forming
control coupling.
External coupling
- refers to the dependence of
multiple modules related to
external factors.

These common external factors


within two modules can be an
input-output device, external files,
infrastructure system or a
communication protocol.
Common Coupling

Two modules are common


coupled if they share information
through some global data items.
Content Coupling: When two modules shared code and can modify the
data of another module, which is the worst coupling and should be
avoided.
Cohesion
Cohesion refers to what module can do, internally. It is also called Intra-
Module binding as it measures the strength of relationship of
functionalities inside a module/package/component.

Cohesion should always be high means that a


module/package/component is focused on what it should be doing, i.e.
only methods relating to the intention of the class.
Types of Cohesion
Functional Cohesion
- is said to exist if the different
elements of a module, cooperate
to achieve a single function.

in a single component, all the


essential functional elements are
combined together for performing
a single computation.
Sequential Cohesion
The output of an element is the
input of other element in a
module i.e., data flow between
the parts.
Communicational Cohesion

Multiple elements in a module


operate on same input data and
produce same output data.
Procedural Cohesion
A module exhibits procedural cohesion when its elements have been grouped together because
they always execute in a particular sequence.
For example, payment processing for a customer placing an order might involve the following
steps being executed in a particular sequence:

Gathering payment information


Validating payment method details
Checking whether funds are available or whether there is enough available credit
Persisting the order in a database
Checking inventory levels
Creating a back order or canceling an order based on inventory
Sending the order for fulfillment
Sending an email confirmation to the customer
Temporal Cohesion
- a module is said to possess
temporal cohesion, where the
components of that program module
get grouped during the time frame
when they get processed.
In other terms, if a component
performs several tasks and the
tasks/functions are related by timing,
the cohesion is said to be temporal.
Logical cohesion
is a concept where all modules
that are logically doing the same
function are put together.
Coincidental Cohesion
A module has coincidental cohesion if its elements have no
meaningful relationship to one another.

- is the result of the unplanned and accidental collection of the


functions

You might also like