SOLID & Design Patterns Interview Question #3
How can you identify an SRP violation?
SOLID Principles, Design Fundamentals, Repository, Factory, Strategy & Decorator Junior Beginner
Quick Interview Answer
A common sign is a class with many unrelated dependencies or methods serving different business concerns. Another sign is that different teams or requirements repeatedly modify the same class for unrelated reasons.
Detailed Explanation
A common sign is a class with many unrelated dependencies or methods serving different business concerns. Another sign is that different teams or requirements repeatedly modify the same class for unrelated reasons.
Large class size alone does not prove an SRP violation. The key question is whether the class has multiple independent reasons to change.
Code Example
// Warning sign: unrelated responsibilities
public class UserManager
{
public void CreateUser() { }
public void SendEmail() { }
public void ExportPdf() { }
public void WriteAuditLog() { }
}