Interview Q&A / Object-Oriented Programming

BeginnerQuick answer1 min readUpdated 3 Oct 2026

Does the Single Responsibility Principle mean a class should have only one method?

SHORT ANSWER

No. It means a class should have one reason to change, serving one actor or concern. A class can have many methods if they all serve that single purpose.

Explain it simply

A cricket scorer keeps runs, wickets and overs. Many actions, but one concern: the score. Adding a "print the ticket" job to the same person would be a second concern.

Count responsibilities by who would ask for changes, not by how many methods exist. If the finance team and the design team both send change requests to the same class, it holds two responsibilities.

Example

java
class Cart {                                   // one concern: the contents of a cart
    void add(Item i) { ... }
    void remove(Item i) { ... }
    int  total() { ... }
    int  count() { ... }
}

class Cart2 {                                  // mixed concerns
    void add(Item i) { ... }
    int  total() { ... }
    void saveToMySql() { ... }                 // storage
    String toInvoiceHtml() { ... }             // presentation
}

Cart has four methods and still follows SRP. Cart2 has the same number and does not.

What to say in the interview

"SRP is about one reason to change, not one method. I judge it by asking which different people or concerns would force an edit to this class. Many cohesive methods are fine; unrelated ones are the warning sign."

Common mistakes

  • Splitting cohesive code into one-method classes just to look tidy.

#solid#srp#design

Related questions

Practise more Object-Oriented Programming questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Object-Oriented Programming quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.