2.2.4 · D1Design Principles

Foundations — SOLID — Single Responsibility Principle

1,752 words8 min readBack to topic

This page builds — from nothing — every word and symbol the parent note SRP topic assumes you already know: class, module, actor, reason to change, coupling, and the small pieces of probability (, , , the power ). Do not skip: even if a word feels familiar, we anchor it to a picture so the rest of the topic clicks.


0. What is a class / module? (the box that holds code)

Before we can say "a class should have one reason to change," we must agree on what a class is.

  • Data (fields): the facts it remembers, e.g. an employee's name, hoursWorked, rate.
  • Methods (actions): things it can do, e.g. calculatePay(), save().
Figure — SOLID — Single Responsibility Principle

Look at the figure: the outer rectangle is the class box. The top drawer holds fields (facts); the bottom drawer holds methods (verbs). Everything SRP talks about is which methods belong in the same box.


1. What is a reason to change? (the heart of everything)

The parent note's entire definition rests on this phrase, so we earn it carefully.

Picture a class box with arrows pointing into it. Each arrow is a person (or role) who might one day say "change this behaviour." If one arrow points in, the box has one reason to change. If two arrows point in, it has two.

Figure — SOLID — Single Responsibility Principle
  • Left box (good): one arrow — one reason to change.
  • Right box (bad): two arrows from two different roles — two reasons to change. When Accounting pulls its arrow, the shared code moves and HR's arrow gets yanked too.

2. What is an actor? (a name for each arrow)

The word "actor" is just a tidy label for "the boss behind an arrow." SRP restated with this vocabulary:

We need the word actor because "reason to change" is abstract, but an actor is a concrete person you can point at on an org chart. That is why the topic keeps saying "which stakeholder asks for this change?"


3. Cohesion and coupling (how tangled the boxes are)

The parent links Cohesion and Coupling and says "SRP is high cohesion + low coupling." We must define both from zero.

Figure — SOLID — Single Responsibility Principle
  • Top pair: high coupling — a taut string means touching one jiggles the other.
  • Bottom pair: low coupling — slack string, each moves freely.

4. The probability toolkit (, , multiplying, powers)

The parent's formula uses four ideas from probability. We build each with a picture — no prior stats needed.

4a. What is a probability ?

Picture a bar of length . Shade a fraction of it — that shaded part is "the change breaks another actor."

4b. Why ? (the complement)

If the shaded part means "breaks," the unshaded part is "does not break." The whole bar is , so:

We use (called the survival probability) because it is easier to ask "did everything survive?" than "did at least one break?" — the survivals multiply cleanly, as we see next.

4c. Why multiply? (independent events)

Suppose two other actors each independently survive a change with probability . "Both survive" is like flipping two coins and asking for two heads. For independent events, you multiply the chances:

Figure — SOLID — Single Responsibility Principle

The figure shows a probability tree: each fork splits into "survive" () and "break" (). Follow the top-top branch (all survive) — you multiply along the path, giving for two actors.

4d. What is the power ?

When one actor makes the request, there are other actors who might get broken. All must survive, so we multiply by itself times. Writing " multiplied times" as a power is just shorthand:

Now the parent's formula reads itself:


5. Two named dangers the topic mentions

Quick anchors so the words aren't scary later:

Also note DRY Principle (Don't Repeat Yourself): sharing a helper to avoid duplication is good — unless the helper is shared by two actors, which secretly re-couples them. That is the trap in the parent's regularHours() example.


Prerequisite map

Class = box of data + methods

Reason to change = arrow in

Actor = the boss behind an arrow

Cohesion = things belong together

Coupling = boxes tied together

SRP = one box one actor

Probability p and 1 minus p

Independent events multiply

Power = repeated multiply

Risk formula R of A


Equipment checklist

What is a class in one line?
A box bundling data (fields) with the operations (methods) that act on it.
What does "reason to change" mean?
A distinct source of future edit requests — an arrow pointing into the class box.
What is an actor?
A single person/role who acts as one source of change requests (e.g. Accounting, HR, DBA).
State SRP using the word actor.
Each class should correspond to exactly one actor.
What is cohesion?
How strongly the things inside one box belong together (ideally: all serve one actor).
What is coupling?
How much two boxes depend on each other; editing one forcing edits in the other.
If is the break probability, what is ?
The survival probability — the chance it does NOT break.
Why do we multiply survival probabilities?
Because independent events combine by multiplication: .
What does stand for and why in the exponent?
= number of actors on the class; = the other actors who could be broken by one actor's request.
What is and why does it matter here?
It equals ; with actor it makes , the SRP-clean case.
Compute for .
.