Object reorientation
summary
Refactors a 1,000‑line nested switch into small rule classes that implement the mod 11 and related checks, extracts about 14 rules from the spec, and expands test vectors until a third of cases fail (revealing hidden bugs). Introduces a value object for bank account + sort code that enforces validation at construction, uses PHP 7 type hints, returns clones or immutable DateTime to avoid accidental mutation, and adds a factory so downstream code always receives a validated object.
AI-written summary · about
chapters (16)
- 0:00Intro
- 2:18Solid
- 5:32Don't repeat yourself
- 9:16Reduce invalid states
- 12:04Objects should always be valid
- 15:25Encapsulate internal state
- 17:48Use type hints
- 19:34Change or return
- 22:07Mutable values
- 27:33A case study
- 29:12Basic validation
- 30:28Mod 11 validation
- 34:12Rule classes
- 35:37The validator
- 36:55A value object
- 39:05The factory








