Cobwwweb logo

WTF is the Single-Responsibility Principle?

Jun 29, 2020 WTF

The single-responsibility principle is somewhat self-explanatory. It means that, in programming, everything — e.g. a class, function, module, plugin — should do one thing.

Some benefits to this approach include:

Because the idea is for code to stay focused on one thing, I often describe this principle as a chunk of code should do one thing and do it well. I say that because I find an implication that by breaking up code into individual responsibilities, the resulting code should be better — more solid and stable, easier to read and understand — than it would have been if responsibilities were combined.

Did you learn something or find this article interesting?

If so, why not

Want to receive exactly one email every month with new articles, tools, and references I've discovered? Sign up below. (More info here.)