Extracting Shared Code After Comparing Behaviors
Two similar-looking routines can be combined when their compatible behavior and meaningful variations are understood.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Trace two importers
Both parse numeric quantities, but one permits zero and the other requires a positive value. A shared parser can convert text while callers supply domain rules. See parsing and validation.
Keep prior callers covered
Use separate tests for boundary cases that each caller relied on before the refactor. Contracts for replacements explain which observations need preservation.[1]