Single responsibility (SRP) 00:00:00 Make a prediction You will find separate reasons for change in an invoice and keep together operations that protect one invariant. A tax rate changes and the receipt font changes. If both require editing the same invoice renderer, what does that suggest? The object mixes calculating a business amount with presenting it. Give each change a clear owner and pass the calculated amount to the formatter. 00:00:26 Lee, the drum and the flute A drummer and a flautist play one piece. Replacing a torn drumskin should not require retuning the flute. The conductor coordinates them but does not manufacture both instruments. Separate work when different people or rules drive its changes. Keep tightly related actions together when they jointly maintain one promise. The single responsibility principle (SRP) says that a class should have one reason to change. It is the S in SOLID. When two groups share a class, a change for one can break the other. The mail text changes on Monday, and on Tuesday the cache is wrong, because both lived in one file and touched the same field. 00:01:08 Who asks for this change? A tax-law change affects how an invoice total is calculated. A new receipt layout affects how that already-calculated total is displayed. Let a tax rule compute the amount and let a formatter consume the finished invoice. Each component has one reason to change. Add a layout field without touching tax calculations. Then change a tax rate and check that the layout continues to display the supplied amount. Ask for a tax-rate change, then independently ask for a wider line on the receipt. The financial result changes in the first test only. The rendered layout changes in the second. If both edits repeatedly affect one owner, those independent requests identify a useful split. 00:01:53 Avoid splitting every method A bank account validates withdrawals and updates its balance. Those steps protect one rule and should stay together. A monthly statement renderer has a separate audience and change history. Split by responsibility and ownership, not by counting methods. Checking the balance and debiting it belong close together, because separating them could allow a stale check followed by a debit. A printable balance display can vary independently. Count reasons to change, not the number of methods, before deciding how many classes to introduce. Splitting validation from updating a balance across disconnected owners can weaken the rule. One method per class is not the objective. Keep withdrawal validation and mutation together, while moving statement layout to the component whose customers request presentation changes. Postfix. The mail server is a group of small programs. One receives, one cleans up, one manages the queue, one delivers. Its overview page gives each program one part of the way of a message. Kubernetes controllers. The documentation says that it is useful to have simple controllers rather than one, monolithic set of control loops that are interlinked. Each tracks at least one kind of resource. 00:03:12 Try an interview follow-up How does the principle look at the level of teams? Actors are teams, so a good cut follows ownership: one team can change and release its part without a meeting. I look at which services are always deployed together and at approvals across teams. If two teams always need each other, the border is in the wrong place, and I move it instead of adding another layer. Payroll asks for a different tax rule. Design asks for a different pay slip layout. If both edits land in the same class, split calculation from presentation. Now test a tax change by checking the amount, and change the layout while keeping that test untouched. The two responsibilities answer to different decision makers. 00:03:59 What to take with you Ask of every class: who could ask for a change here? One answer is fine. Two answers are two classes, joined by a thin coordinator that knows only the order. Split by actor, not by size. A long class with one owner can stay. A short method shared by payroll and planning must go apart.