SOLID in one page
medium 45 minFive principles for classes that can be changed without fear: single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion.
Watch lesson5:16
Verify
Five checks with numbers, and the original program beside the new one.
The point: do not claim SOLID, show it. One check per letter, and each can fail.
Checks
One test per letter
| Letter | Check | Result here |
|---|---|---|
| S | Name the actor of each class | Operations: text. Delivery team: senders. Monitoring: service |
| O | Add a kind and read the diff | One class, one line of wiring |
| L | Run the contract test for each kind | Three pass. The cutting SMS of the first version fails |
| I | Count unused methods per implementer | 0 |
| D | Which imports does the service need? | Only data and ports |
Trace of one bad evening
| Step | Returns | History |
|---|---|---|
| format | [CRITICAL] db1: disk 95% full | |
| email.send | Receipt(False, smtp down) | email failed: smtp down |
| sms.send | Receipt(False, no number for ops) | sms failed: no number for ops |
| chat.send | Receipt(True) | chat ok |
| notify | 1 | 3 entries |
The five wishes again
| Wish | Before | After |
|---|---|---|
| Host in the text | AlertManager | AlertFormatter and the data |
| Chat | AlertManager | ChatSender, wiring |
| SMS loses text | AlertManager | SmsSender, and a test for all |
| Read replies | A stub in every kind | ReplyReader for two kinds |
| Test without server | Not possible | A fake of three lines |
| Read everything at once | 12 lines | About 60 lines in 8 classes |
Is it worth it here?