How do you spot a Single Responsibility violation in real code?
Look for a class whose description needs the word and, imports from unrelated areas, unrelated groups of fields, or edits from different people for different reasons.
Explain it simply
Imagine describing a class to a friend. If you say "it validates the form and sends the email and writes to the log", you have found three jobs. Other clues: the class imports both a database library and a PDF library; some methods use half the fields and other methods use the other half; merge conflicts keep happening in one file between teammates working on unrelated features.
Example
class OrderService {
private Connection db; // used by save()
private SmtpClient smtp; // used by notify()
private TaxTable taxTable; // used by price()
Order price(Cart c) { ... } // uses taxTable only
void save(Order o) { ... } // uses db only
void notify(Order o) { ... } // uses smtp only
}The fields split into three groups, and each method touches just one group. That is a strong sign of three classes hiding inside one.
A useful quick test: can you write the class's job in one sentence without "and"?
What to say in the interview
"I look at the reasons it would change. Signs are an and in its description, unrelated dependencies, methods that use separate groups of fields, and frequent merge conflicts. The fix is to extract each concern into its own class."
Common mistakes
- Treating class size alone as proof. A large cohesive class can be fine.