The Clock Is a Dependency
Easy About 20 min Katabench Pro
A hotel's cancellation rule and its receipts both read a static infrastructure clock, so the core depends outward and nobody can choose the date it runs against. Hand the core a clock through its constructor and the domain a plain date, so a service that runs for days still dates every cancellation correctly.
The full brief is part of Katabench Pro
Pro opens this kata's brief, its starter code and its grader. To see how the track works first, try Config Is Infrastructure, which is free.
How it is graded
You work across multiple files, and architecture rules turn the design boundaries into executable feedback.
What it practices
- Infrastructure as adapters
- Keep the ORM, clocks, caches, configuration and startup work out of the core as replaceable adapters.
- Dependency injection
- Ask for collaborators through constructors instead of newing them up or locating them.
Related katas
- Config Is Infrastructure Medium Free The shipping core reads a framework configuration type directly, welding the domain to infrastructure. Invert it behind a core-owned options port, and don't just rename the framework wrapper into the core, which trips a second rule.
- Fakes Don't Ship Easy Pro A test stub lives in the core and the checkout quietly falls back to it when nobody injects a gateway. Evict the stub to the testing namespace and make the dependency mandatory; a convenient default is a production code path.
- Keep Startup Out of Requests Easy Pro The search request path initializes its index on every call. Keep bootstrap work at the host boundary and lend the application only the initialized query capability.
- New Is Glue Easy Pro The port exists, the adapter implements it, and the core news the concrete anyway. One
newin the wrong place welds the core to infrastructure; hand the wiring to the composition root.