2.2.4 · D3Design Principles

Worked examples — SOLID — Single Responsibility Principle

2,304 words10 min readBack to topic

This is a companion to the parent SRP note. Read that first — here we only apply it, exhaustively.


The scenario matrix

Before working examples, let us list every cell a SRP question can fall into. Think of it like listing every quadrant before doing trigonometry: if a case is on this table, you will see a worked example for it below.

# Cell (case class) What makes it distinct Worked in
C1 Clean class, many methods Many operations but ONE actor → not a violation Ex 1
C2 Two actors, shared helper The classic god-class; DRY re-couples actors Ex 2
C3 Three+ actors Full extract + Facade; risk formula bites hardest Ex 3
C4 boundary Degenerate: one actor → Ex 4
C5 boundary Degenerate: no actor → dead code, undefined-ish Ex 4
C6 Risk formula limiting behaviour , , Ex 5
C7 Over-split (SRP misapplied) Too many tiny classes → shotgun surgery Ex 6
C8 Word problem (real org) Map methods → stakeholders from a story Ex 7
C9 Exam twist: looks-bad-but-clean Two methods, but same actor → trap Ex 8
C10 Numeric comparison Quantify "before vs after" a split Ex 9

Each example below is tagged with the cell it fills. Together they cover all ten.


Reading the risk formula visually first

Every numeric example uses . Before plugging numbers, see it.

Figure — SOLID — Single Responsibility Principle

Look at the red curve: with break-probability fixed, adding actors ( on the horizontal axis) pushes risk upward, fast at first then flattening toward . The single black dot at sits exactly on — an SRP-clean class carries zero cross-actor risk. That dot is the goal of every refactor.


Worked examples

Ex 1 — Clean class, many methods (cell C1)


Ex 2 — Two actors, shared helper (cell C2)


Ex 3 — Three or more actors + Facade (cell C3)

Figure — SOLID — Single Responsibility Principle

The red block (the tangled god-class) fans out into three isolated black boxes, each owned by exactly one actor; the Facade is the single door back in.


Ex 4 — The degenerate counts and (cells C4, C5)


Ex 5 — Limiting behaviour of the formula (cell C6)

Figure — SOLID — Single Responsibility Principle

Three red curves for : all start at when and climb toward the black ceiling line — steeper for bigger .


Ex 6 — Over-split (SRP misapplied) (cell C7)


Ex 7 — Word problem: a real org (cell C8)


Ex 8 — Exam twist: looks-bad-but-clean (cell C9)


Ex 9 — Numeric before/after comparison (cell C10)


Recall

Which cell does a class with 8 methods but one stakeholder fall in? ::: C1 — clean, many methods, , no violation. Why is negative and what does it really mean? ::: The derivation assumes ≥1 actor; is dead unowned code, outside the formula's domain (not a real probability). As with , what does approach and why? ::: ; each extra actor multiplies in another , driving the "nobody broken" chance to . What smell does over-splitting into one-method classes create? ::: Shotgun surgery — one conceptual change now edits many files. For , what is the before-refactor risk? ::: .


Connections

  • SOLID — Single Responsibility Principle — the parent rule these examples exercise.
  • God Object (anti-pattern) — Ex 3 & the limit in Ex 5.
  • Shotgun Surgery — the over-split smell in Ex 6.
  • Facade Pattern — the single door-back in Ex 3 & Ex 7.
  • Cohesion and Coupling — the risk drop is coupling, measured.
  • DRY Principle — the shared helper trap in Ex 2.
  • Open-Closed Principle — after splitting, extend without editing.