Cohesion

Senthil Nayagan
1 min readMay 1, 2018

--

Cohesion in computer programming is the degree to which the elements of a certain module (class in our case) belong together.

Thus, cohesion measures the strength of relationship between pieces of functionality within a given module.

Simply, all the related code should be close to each other.

Cohesion is usually described as:

  • High Cohesion
  • Low Cohesion

High Cohesion

Modules with high cohesion tend to be preferable, because high cohesion is associated with several desirable qualities of software including:

  • Robustness
  • Reliability
  • Reusability
  • Understandability

High cohesion means that class should do one thing and one thing very well.

Low Cohesion

Low cohesion is associated with several undesirable qualities such as:

  • Being difficult to maintain
  • Difficult to test
  • Difficult to understand

Conclusion

High cohesion and low coupling give us better designed code that is easier to maintain.

--

--

Senthil Nayagan
Senthil Nayagan

Written by Senthil Nayagan

I am a Data Engineer by profession, a Rustacean by interest, and an avid Content Creator.

No responses yet