You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Single Responsibility Principle is about actors and high-level architecture. It states that “A class should have
only one reason to change.” This means that every class should _only_ have responsibility over a single part of the
functionality provided by the software. The largest benefit of this approach is that it enables improved code
_reusability_. By designing our class to do just one thing, we can use (or re-use) it in any other program without
changing it.
I remembered reading a blog post a few weeks ago about how the idea that SRP meant "one class should only do one thing" was a misunderstanding of the principle.
Instead, the original meaning of this principle would be that only one "actor" should be able to cause a change in a given module (here a class), implying that if the module tries to address multiple business needs at the same time, those different business needs might end up conflicting and will make later changes harder.
So I don't think the SRP is about code reusability, I think it is about maintainability and ease of following business changes.
Here are a few posts I found about it (I cannot remember the post I originally read about this misunderstanding):
Hello!
I have read the SRP definition on the website. As a reminder, here is how it is currently described:
php-the-right-way/_posts/06-03-01-Complex-Problem.md
Lines 27 to 33 in 4e688e0
I remembered reading a blog post a few weeks ago about how the idea that SRP meant "one class should only do one thing" was a misunderstanding of the principle.
Instead, the original meaning of this principle would be that only one "actor" should be able to cause a change in a given module (here a class), implying that if the module tries to address multiple business needs at the same time, those different business needs might end up conflicting and will make later changes harder.
So I don't think the SRP is about code reusability, I think it is about maintainability and ease of following business changes.
Here are a few posts I found about it (I cannot remember the post I originally read about this misunderstanding):
What do you think about this? Should we change the description of this principle on PHP the right way?
The text was updated successfully, but these errors were encountered: