Skip to main content
PreparationZone Logo
PrepZone

Single Responsibility in Real Systems

Split classes by reason to change, not by line count.

Pass checkpoint below

Why this matters

  • A class should have one reason to change — one stakeholder group whose decisions affect it
  • High cohesion: methods share a single purpose and reuse private state
  • Before: one InvoiceService with tax, HTML, and SMTP inline
  • Do not create one class per method — that is over-engineering
  • SOLID is scored as refactor skill, not acronym recall.
SRPOne reason to change
OCPExtend, don't modify
LSPSubtypes substitutable
ISPSmall interfaces
DIPDepend on abstractions
Each principle maps to a class-design smell interviewers probe.

Overview

Split classes by reason to change, not by line count. Study each section below in order — every list is interview-ready reference material.

Reasons to change

Points to cover

  • A class should have one reason to change — one stakeholder group whose decisions affect it
  • Invoice example: tax rules, report format, and email delivery are three reasons → three classes
  • OrderService should coordinate, not implement tax math or HTML rendering
  • Ask aloud: 'If I change X policy, which classes must I edit?'
  • More than one answer → split responsibilities

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • Cohesion test
  • CampusOS invoice refactor
  • When not to split

Test yourself

Answer these before moving on — recall is what makes it stick.