SerialDate: Cleanup & Transformation
Apply successive refinement to the SerialDate class — test, rename, extract, and simplify.
Rename First, Then Extract
After diagnosis, start with the simplest change: rename. SerialDate → DayDate. getSerial() → toOrdinal(). Renaming is low-risk and immediately communicates intent. Only after renaming should you extract static utilities into separate helper functions or classes.
Tests as Documentation
Each refactoring step should produce passing tests. If a step breaks tests, it revealed a hidden dependency — a gift. Tests written during cleanup become the permanent specification of the class. By the end, the test suite describes what the class does better than any comment ever could.
Code Challenge
Apply rename and extract transformations to the SerialDate class.
💡Key takeaway
Refactoring is not rewriting. It is a series of small, safe, behaviour-preserving transformations — each one making the code slightly more expressive.
🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.
Hint: Cleanup is not rewriting — it's renaming, extracting, and removing until the code speaks for itself.
✗ Your version