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 software
We always strive for high cohesion
Types of cohesion
- A module that performs tasks that are related logically is logically cohesive.
- When a module contains tasks that are related by the fact that all must be executed with the same span of time, the module exhibits temporal cohesion.
- At the low-end of the spectrum, a module that performs a set of tasks that relate to each other loosely, called coincidentally cohesive.
As an example of low cohesion, consider a module that performs error processing for an engineering analysis package.
The module is called when computed data exceed pre-specified bounds. It performs the following tasks:
(1) computes supplementary data based on original computed data,
(2) Produces an error report (with graphical content) on the user's workstation,
(3) Performs follow-up calculations requested by the user,
(4) Updates a database, and
(5) Enables menu selection for subsequent processing. Although the preceding tasks are loosely related, each is an independent functional entity that might best be performed as a separate module.
Combining the functions into a single module can serve only to increase the likelihood of error propagation when a modification is made to one of its processing tasks.