Skip to content

Single Responsibility Principle definition #906

Open
@cGuille

Description

@cGuille

Hello!

I have read the SRP definition on the website. As a reminder, here is how it is currently described:

#### Single Responsibility Principle
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):

What do you think about this? Should we change the description of this principle on PHP the right way?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions