SteelReed

Search

Search posts, questions…

OOP & DesignQuestion 10 / 42

Middle

What is a responsibility in SRP, how do you spot a violation, and how does ISP differ?

Short answer

A responsibility is a reason to change, tied to one actor (accounting, HR, the DBA); a class breaks SRP when several actors all need to change it. ISP: don't force a client to depend on methods it doesn't use.

calculatePayreportHourssavesplit by actorAccountingEmployeeHRDBAThree separate classes

3 points to say:

  1. Responsibility = reason to change = one actor; share a helper between two actors and a change for one breaks the other.
  2. Warning signs: git history changing for many reasons, low cohesion, many dependencies, vague names.
  3. SRP splits classes by source of change; ISP splits interfaces by what callers need.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.