Home
Home
All Posts

WTF is the Single-Responsibility Principle?

I often talk about the single-responsibility principle in the articles I write. What does it really mean? (Spoiler: It's probably exactly what you think.)

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.

Want to receive approximately one email every month with new articles, tools, and references I've discovered? Sign up below.

Read past issues.

Home
Social Links
Site References