madhavrao… » Cohesion

Cohesion

Cohesion: Cohesion is a measure of how strongly related and focused the responsibilities of an element are. An element with highly related responsibilities, and which does not do a tremendous amount of work, has high cohesion. These elements includes classes, subsystem and so on. A class with low cohesion do many unrelated things, or does too much of work. Such classes suffer from the following problems:

  • hard to comprehend
  • hard to reuse
  • hard to maintain
  • delicate; constantly effected by change

Types of Cohesion

The types of cohesion, in order of worst to best are as following:

  • Coincidental Cohesion
  • Logical Cohesion
  • Temporal Cohesion
  • Procedural Cohesion
  • Communicational Cohesion
  • Sequential Cohesion
  • Functional Cohesion

Coincidental Cohesion (worst): Coincidental cohesion is when parts of a module are grouped arbitrarily (at random); the parts have no significant relationship (e.g. a module of frequently used mathematical functions).

Logical Cohesion: Logical cohesion is when parts of a module are grouped because they logically are categorized to do the same thing, even if they are different by nature (e.g. grouping all I/O handling routines).

Temporal Cohesion: Temporal cohesion is when parts of a module are grouped by when they are processed - the parts are processed at a particular time in program execution (e.g. a function which is called after catching an exception which closes open files, creates an error log, and notifies the user).

Procedural cohesion: Procedural cohesion is when parts of a module are grouped because they always follow a certain sequence of execution (e.g. a function which checks file permissions and then opens the file).

Communicational cohesion: Communicational cohesion is when parts of a module are grouped because they operate on the same data (e.g. a module which operates on the same record of information).

Sequential cohesion: Sequential cohesion is when parts of a module are grouped because the output from one part is the input to another part like an assembly line (e.g. a function which reads data from a file and processes the data).

Functional cohesion (best): Functional cohesion is when parts of a module are grouped because they all contribute to a single well-defined task of the module

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>