Why single responsibility is important?

Why single responsibility is important?

The single responsibility principle is one of the most commonly used design principles in object-oriented programming. You can apply it to classes, software components, and microservices. It also lowers the complexity of each change because it reduces the number of dependent classes that are affected by it.

Which principle says that a single class should have one and only reason to change?

The Single Responsibility Principle (SRP) states that a class should have only one reason to change. It was first cited in this form by Robert C. Martin in an article that later formed a chapter in his Principles, Patterns, and Practices of Agile Software Development book.

When do we need to change in a class having more responsibilities?

When we need to make a change in a class having more responsibilities the change might affect the other functionality related to the other responsibility of the class. The Single Responsibility Principle is a simple and intuitive principle, but in practice it is sometimes hard to get it right. A class should have only one reason to change.

What is the real responsibility of a class?

First of all, the so called “Single Responsibility Principle” is a reflex — explicitly declared — of the concept cohesion. Reading the literature of the time (around ’70), people were (and still are) struggling to define what a module is, and how to construct them in a way that would preserve nice properties.

Who is the originator of the single responsibility principle?

All of that module, class or function’s services should be narrowly aligned with that responsibility. Robert C. Martin, the originator of the term, expresses the principle as, “A class should have only one reason to change,” although, because of confusion around the word “reason” he also stated “This principle is about people.”.

When is a responsibility considered a reason to change?

In this context, a responsibility is considered to be one reason to change. This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one responsibility and if in the future we need to make one change we are going to make it in the class which handles it.