Skip to main content
Clean Code 60 XP · 6 min

Responsibility Selectors

Use the Single Responsibility heuristics to detect and split overloaded classes and modules.

Showing
Ad (728×90)

The "And" Test

Describe what a class does. If the description requires the word "and", split the class. A UserService that validates users and sends emails and formats reports has three responsibilities.

The Change Reason Test

A class has too many responsibilities if multiple different stakeholders — the DBA, the UI team, the business analyst — would each request changes to it. SRP: a class should have only one reason to change.

Code Challenge

Apply the 'and' test to split the overloaded class.

Key takeaway

Small, focused classes are easier to name, test, and reuse. If you struggle to name a class, it probably does too much.

Done with this lesson?

Mark it complete to earn XP and track your progress.