ByteMonk logoByteMonk

System Design · LLD Foundations

SOLID · Single Responsibility: One Reason to Change

SRP is the most quoted and most misunderstood principle in software. Learn the "reason to change" test and apply it to a class interviewers love to hand you.

3 min read · solid · srp · design-principles

Everyone can recite it: "a class should have only one reason to change." Almost nobody can apply it under pressure. The gap is that SRP isn't about class size. It's about who asks for changes.

chatgpt image aug 31 2026 11 08 21 pm 1

The test: count the stakeholders

A "responsibility" is a source of change requests. If the pricing team, the compliance team, and the platform team can all force edits to the same class, that class has three responsibilities, even if it's forty lines long.

InvoiceManagercalc · persist · printPricing teamDBA / platformCompliance3 stakeholders= 3 reasons to change= SRP violation
One class, three masters: every arrow is a future merge conflict.

The class interviewers love to hand you

Here's the classic bait. It looks tidy. It compiles. It ships.

InvoiceManager.java: the trap
public class InvoiceManager {
    public Money calculateTotal(Invoice invoice) {
        // tax rules, discounts, rounding policy
    }
 
    public void saveToDatabase(Invoice invoice) { /* JDBC everywhere */ }
 
    public String renderPdf(Invoice invoice) { /* fonts, layout, logos */ }
}
ChatGPT Image Aug 29, 2026, 11 18 22 PM (6)

Ask the stakeholder question: tax rules change (finance), storage moves to a new schema (platform), the PDF gets a rebrand (design). Three teams, three reasons, one file. Every change risks the other two behaviors, and the unit tests now need a database and a PDF renderer just to verify a tax rule.

The fix is unglamorous and that's the point:

After SRP: three axes of change, three homes
public class InvoiceCalculator {          // changes when business rules change
    public Money calculateTotal(Invoice invoice) { /* ... */ }
}
 
public class InvoiceRepository {          // changes when storage changes
    public void save(Invoice invoice) { /* ... */ }
}
 
public class InvoicePdfRenderer {         // changes when presentation changes
    public String render(Invoice invoice) { /* ... */ }
}

How this shows up in your interview

You'll rarely be asked "explain SRP." Instead, it's embedded in the follow-ups of every design question. In the parking lot: should ParkingLot compute fees? No: fees change with business whims (weekend pricing, EV discounts), while the lot's structure doesn't. That instinct, "pricing will change on its own schedule, so it gets its own class", is SRP, spoken like an engineer instead of a textbook.

✎ Check yourself

A `ReportGenerator` fetches data, computes stats, and emails the result. The email provider is being replaced next quarter. What does SRP suggest?

like?