My take on the Single Responsibility Principle

by Jason Swett,

The Single Responsibility Principle (SRP) is an object-oriented programming principle that says (more or less) that each object should only have one responsibility.

The main difficulty that I’ve seen others have with the SRP, which I’ve also had myself, is: what exactly constitutes a single responsibility?

The answer I’ve arrived at is that it’s a subjective judgment what constitutes a single responsibility. If I write a class that I claim has just one responsibility, someone else could conceivably look at my class and credibly argue that it has eight responsibilities. There’s no way to look at a class and objectively count the number of responsibilities it has.

Here’s how I would characterize the gist of the Single Responsibility Principle: things that are small and that are focused on one thing are easier to understand than things that are big and contain a large number of things. Understanding this principle is much more helpful than understanding exactly what a “single” responsibility is.

Leave a Reply

Your email address will not be published. Required fields are marked *