Tuesday, October 20, 2015

Filled Under: ,

Cohesion in C language

Definition: The cohesion of a module is a measure of how well it fits together. A module should implement a single logical function or should implement a single logical entity.

Cohesion is used to measure strong relationship and responsibilities of a module. Cohesion is generally expressed as "high cohesion" or "low cohesion". Modules with high cohesion are preferable. High cohesion is associated with several desirable qualities of program. They include consistency, re-usability, and understand-ability. Low cohesion is associated with undesirable qualities such as difficulty in maintenance, difficulty in testing, difficulty in reusing and understanding.

Cohesion is more difficult to measure directly because it is a measure of the meaning of relationships. Cohesion is reduced when the responsibilities of a module have little in common and the module carries out different operations using unrelated set of data. Thus, the disadvantages of low cohesion result into:

Disadvantage
Reason
Difficulty in understanding modules
Module carries out unrelated operations.
Difficulty in maintaining a program
Logical changes in one module affected the multiple related modules.
Difficulty in reusing a module
Most of the application programs would not need the arbitrary set of operations provided by a module.

The levels of cohesion can be divided into seven levels in the order of worst to best as follows:
  1. Coincidental
  2. Logical
  3. Temporal 
  4. Procedural
  5. Communicational
  6. Informational
  7. Functional

In case of coincidental level of cohesion, no particular relations among operations exists within a module. The existence of the operations within a module are just unplanned ones. 

In case of logical level of cohesion, a set of related operations exist with a choice for calling. 
In case of temporal level of cohesion, a series of operations are related with respect to the time of using such operation. It means the relationship is for sequencing the order of operations. The operations here typically have strong connections with other parts of the program.

In case of procedural level of cohesion, there exist a series of operations that have something to do with each other. With such relationship the overall problem is being solved.

In case of communicational level of cohesion, there exist a series of operations similar to procedural cohesion, but applied to the same data. 

In case of informational level of cohesion, there exist a group of tasks that work on the same data model.

In case of functional level of cohesion, there exist a course of action that accomplishes one clear function. This is the best level of cohesion.

So, to design a program the programmer must try to maximize the cohesion. The modules whose elements are strongly and fully related to each other are desired. A module should be highly cohesive.

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

© 2013 iPRESS. All rights resevered. Designed by Templateism