Part 2 of 7 · 1 min read
The idea
A class should have one reason to change.
Think of a small shop with one till. The owner, the accountant and the delivery driver all use that till for different jobs. If the accountant asks for a new report layout, the driver's screen must not break. The till does too many jobs for too many people.
The first form of SRP says that each module needs a single cause for editing it. CA points out that this wording is easy to misread, because programs change for many reasons. It gives a sharper version: a module should answer to a single actor. An actor here means one group of people (or one role) who ask for changes in the same way.
So the test is not "how many things does this class do". The test is "how many different groups would ask me to edit this class". If the answer is two or more, the class has two or more responsibilities.
Single responsibility principle
The single responsibility principle says that a class should be written for one actor, so that a change requested by one group never forces edits that matter to another group.
Example: a Payslip class that only the payroll team ever asks to change.
Actor
An actor is one group of users or stakeholders who want the code to change for the same kind of reason.
Example: the finance team asks for new overtime rules, and the HR team asks for new report columns. These are two actors.
Check yourself: 1. What does the sharper version say a module should answer to? 2. A class is edited by finance and by HR. How many responsibilities does it have? 3. Why is "it does many things" not a good test on its own?