Skip to main content
InterviewHubPRO
Section Overview
Q36

Question 36 of 50

Part 3: Enterprise Architecture, Package Design & Enforcement (25 - 35)

72%
SOLID & OOP Principles (50 Qs)•Part 3: Enterprise Architecture, Package Design & Enforcement (25 - 35)

Single Responsibility Principle (SRP) and the "Reason to Change": Actor-driven responsibilities.

senior LevelSystem Design

In Simple Words: Robert C. Martin ("Uncle Bob") refined SRP: "A module should be responsible to one, and only one, actor (stakeholder/user group)":

  • The Violation Example: An Employee class containing calculatePay() (owned by CFO/Finance), reportHours() (owned by COO/Operations), and save() (owned by CTO/Database Admins).
  • The Consequence: When Finance requests a change to overtime calculation, the edit inadvertently breaks the Operations timesheet report, causing merge conflicts and production bugs.
  • The Fix: Separate into independent classes (PayCalculator, HourReporter, EmployeeRepository) operating over a shared immutable data structure.