Skip to main content

Sign in to CleanKata

Track your progress, earn XP, and unlock every lesson.

By signing in you agree to our Terms of Use and Privacy Policy.

Clean Code60 XP6 min

Responsibility Selectors

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

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.

🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.

Hint: The 'and' test: if you need 'and' to describe a class, split it. A class should have one reason to change.

✗ Your version