Cohesion (computer science)

In object-oriented programming Cohesion describes how well a program unit maps a logical task or unit. In a system with strong cohesion each program unit (a method, a class or a module ) is responsible for exactly one well-defined task or unit.

Strong cohesion

The Single Responsibility Principle states that each class has only to fulfill exactly a clearly defined task. This object is achieved by the interaction of all the attributes and methods of this class. The interplay of the attributes and methods of this class is thus very closely. One speaks of strong cohesion.

Poor ( low ) cohesion should be avoided. It leads, among other things, that common features of a class are not reused but are implemented several times. Code duplication is thus a sign of weak cohesion. The DRY principle ( Do not Repeat Yourself - Do not Repeat ') helps to prevent this.

Types of Cohesion

Cohesion can be considered as a qualitative measure of the source code. This measurement can be divided into categories, which differ in the strength of cohesion. Possible categories of cohesion of weak cohesion ( to avoid ) to strong cohesion ( desirable ) are:

Closely associated with the concept of cohesion is the notion of coupling.

Footnotes

  • Object-Oriented Programming
482107
de