32

Refactor, rewrite, or strangler fig

An incremental strangler-fig migration of a legacy fee calculator behind a stable interface.

Demo 32Source on GitHub ↗

Deciding among in-place refactor, rewrite, and the strangler fig, then a worked strangler migration. This module keeps a legacy accessorial-fee calculator (with three undocumented carrier rules) running behind a stable interface, adds a clean modern reimplementation proven equivalent, and routes each shipment to the legacy or modern path through a StranglerFeeCalculatorRouter driven by a migration registry. Traffic moves slice by slice and the total fee stays identical across the cutover.

The JUnit 5 + Mockito tests pin the legacy behavior, prove old and new agree, and verify the router sends each shipment to the right implementation.

Build, run, observe

cd examples/32-refactor-rewrite
mvn -q test
./demo.sh

The module also runs from the aggregator root with mvn -q -f examples/pom.xml test.