types of cohesion in software engineering | Csmates.com

Sonu Tewatia
4 min readNov 15, 2020

--

Module cohesion in software engineering

The notion of cohesion was introduced with coupling in the mid-1970s, also as a way of characterizing good procedural program design.

Cohesion is the measure of strength of the association of elements within a module. In other words, the extent to which all instructions in a module relate to a single function is called Cohesion. In a truly cohesive module, all of the instructions in the module pertain to performing a single unified task. It is also referred as Intra-module Cohesion.

Cohesion is the property or characteristic of an individual module.

Cohesion in modules should be maximized. Maximally cohesive modules also tend to be the most loosely coupled, so achieving high levels of cohesion in the system design also helps minimize coupling.

If a module is designed to perform one and only one function then it has no need to know about the interior workings of other modules. The cohesive module only needs to take data it is passed, act on them, and pass its output on to its super-ordinate module.

A module cohesion is determined by such considerations.

  • Cohesion is highest in modules that have a single, clear, logically independent responsibility.
  • Cohesion degrades as unrelated responsibilities or tasks are added to module.
  • One practical and long-standing practice for achieving cohesion is to form modules that implement data types.

Novice designers often have a tendency to assign responsibilities to software components arbitrarily, destroying module cohesion.

One of the great advantages of the object-oriented analysis and design paradigm is that it encourages designers to create components that mimic real-world entities. Real-world entities tends to have appropriate responsibilities, so modelling them in software generally produces cohesive modules.

types of module cohesion in software engineering

Various levels of cohesion were defined based on the functionality placed in a module. Low cohesion modules included functionality by accident or because of temporal coincidence or logical similarity, while high cohesion modules performed a single action or did a single operation on a data structure.

Here, seven types of cohesions.

  • The name of module will indicate its functions.
  • All statement within a module are based on one function.
  • It is the best cohesion as the module perform a single specific function.

example. We are taking example of Calculating_Sales_Tax function.

IF PRODUCT IS SALES_TAX EXEMPT THEN

IF PRODUCT_PRICE < $100 THEN

SALES_TAX = PRODUCT_PRICE * 0.25

  • The instruction inside a modules are related to each other through the input data.
  • The first instruction acts on the data that are passed into the module, the second instruction use the output of the first instruction as its input and so on.
  • Sequence of events is very important.

Example.We are taking example of the modules that will calculate TOTAL_PURCHASES first, then use the variable TOTAL_PURCHASES in the subsequent calculation of AMT_DUE function.

DO LOOP_INDEX = 1 TO NO_OF_PURCHASES

ADD PURCHASES TO TOTAL_PURCHASES

SALES_TAX = TOTAL_PURCHASES * SALES_TAX_PERCENT

AMT_DUE = TOTAL_PURCHASES + SALES_TAX

  • The activities are related to each other by the data that the modules uses.
  • Each instruction acts on the same input data or is concerned with the same output data.
  • Sequence is not important

Example. Elements of module operate on data that necessary to produce ERR_REPORT

IF_TRAN_TYPE NOT = ‘0’ THEN

IF CUST_NONOT NUMERIC THEN

  • The instruction in a module are related to each other through flow of control.
  • The instruction are grouped together because of a particular procedural order.
  • Sequence is important.
  • The instruction are more related to each other modules than they are to each other.

Example. ‘AND’ word means which module perform more than 1 function.

READ_STUD_REC_AND_TOTAL_STUDENT_Ages

  • The instruction in a module are related to each other through flow of control.
  • The instruction are grouped together because they occur at about the same point in time.
  • These instructions perform more than one functions.
  • e.g. the initializing module at the beginning of program which contain initialization step without affecting other modules.

Example. The element related by time-which is at the beginning of program. The elements perform more than one function.

ISSUE PROMPT ‘ENTER DATE — DDMMYY

  • The instruction are hardly related to each other at all.
  • The instruction are grouped together due to certain classes.
  • A flag that is passed from outside will determine which set of instruction is to be executed.

Example. “ READ_ALL_FILES” is the class — three functions group together due to certain class of activities.

READ_ALL_FILES
CASE OF FILE_CODE

INCREMENT CUST_TRAN_COUNT

INCREMENT CUST_MASTER_COUNT

3: READ PRODUCT_MASTER REC

INCREMENT PRODUCT_MASTER_COUNT

  • The instruction has no relationship to each other at all, they just coincidental fall in the same module.
  • It is the worst type of cohesion.

Example. No meaningful relationship to each other, just coincidentally fall in same module.

OPEN EMPLOYEE UPDATE FILE

OPEN MASTER FILE(EMPLOYEE)

Originally published at https://www.csmates.com.

--

--

Sonu Tewatia
Sonu Tewatia

Written by Sonu Tewatia

Software Engineer | Content Writer | Programmer | System Admin | Linux Administration |

No responses yet