Cohesion and Single Responsibility Principle

Connect with

According to English dictionary Cohesion means “sticking together” but as per design principle what it means? Sometimes in the mid or senior level interview, interviewer coined these terms to check the basic of design principle.

SRP ( Single Responsibility Principle)

“A class should have only one reason to change”

What does it means in the software engineering? When we talk about the design principle we always talk about the best practices. When we design a component we always keep few thing in mind like Single Responsibility, here Responsibility means task to adhere to class . More responsibility to a class it means more reason to change.

Cohesion

High Cohesion is a desirable state

In software engineering while designing a component , Cohesion term used to measure of how closely a class or a module supports a single purpose or responsibility. Classes that adhere to the principle tends to have high cohesion. If class or module having high cohesion it means its a good practices or you can say its desirable state. Classes having multiple responsibilities means multiple reason to change that class, it means low cohesion which is undesirable state in software engineering practices.

Key Points

  • Cohesion is more general concept than Single Responsibility Principle, but the two are closely related.
  • Classes that adhere to the principle tends to have High Cohesion.
  • Single Responsibility Principle and High Cohesion goes hands-in-hands.

Suggestions are welcome, please write your comment to improve this post of Cohesion vs SRP ( Single Responsibility Principle).


Connect with

3 thoughts on “Cohesion and Single Responsibility Principle

  1. Pingback: notName
  2. Pingback: kumud
  3. Pingback: 2019

Leave a Reply

Your email address will not be published. Required fields are marked *