Monday, July 16, 2007

COHESION

A module is defined 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. ”
To rate a module we examine two factors: -

Coupling - This is the degree of interaction between modules; i.e. their inter-relationships

Cohesion – This is the degree of interaction between statements in a module.

* Good modules exhibit low coupling but high cohesion


Cohesion

There are several types of cohesion. We rank them going from the worst form of cohesion to the best

· Coincidental
· Logical
· Temporal
· Procedural
· Communicational
· Informational
· Functional

Coincidental Cohesion: This is the worst form of cohesion. This is where a module performs multiple unrelated tasks. This may occur if modules are not properly designed.

Logical Cohesion: Here modules can perform a series of related tasks, however only one is selected by the calling module.

Temporal Cohesion: The module performs a series of actions that are related in time. E.g. all startup/shutdown activities are brought together.

Procedural Cohesion: Here elements in a module perform a sequence of steps to be followed by the product. The elements in the module thus make up a single control sequence and must be executed in specific order.

Communicational Cohesion: All elements operate on the same input data set or produce the same output data set.

Informational (Sequential) Cohesion: Output from one element in the module serves as input for some other element. Unlike logical cohesion the code for each action is completely independent. A module with informational cohesion is essentially an ADT (abstract data type) and all the benefits of using an ADT are gained when this type of cohesion is employed in a module. Such a module operates on the same data structure. Objects (when well designed) are modules that exhibit informational cohesion.

Functional Cohesion: Module contains elements that perform exactly one function or achieves a single goal.

No comments: