Table of Contents
- Month 5 · Week 3 — Exercises (architecture, DI, domain modeling, caching)
- How to run
- Prompts
- Results
Month 5 · Week 3 — Exercises (architecture, DI, domain modeling, caching)¶
Standard-library-only Go packages with table-driven tests. They rebuild the
architectural mechanics of Week 3 — ports & adapters, value objects, and the
cache-aside pattern — so go test runs anywhere with no wire, no Redis, and
no network.
How to run¶
go test ./exercises/month-05/week-3/...
# or one at a time, verbose:
go test -v ./exercises/month-05/week-3/ports
Prompts¶
-
ports/— Build a hexagonal slice: aTaskentity, aTaskRepositoryOUTBOUND port defined next to its consumer, aServicethat depends on the port via constructor injection, and an in-memoryMemRepoadapter. Enforce domain sentinels (ErrNotFound,ErrExists,ErrEmptyID) and wrap with%wsoerrors.Ismatches. A fake adapter proves the service delegates only through the port. Concepts: ports & adapters, dependency inversion, constructor injection (Days 127–128). -
money/— Implement aMoneyVALUE OBJECT: a validatingNew(3-letter ISO code, normalized/upper-cased),Add/Subthat refuse mismatched currencies (ErrCurrencyMismatch), value equality via==(comparable struct), integer minor-units, and a sign-awareString(). Fields are unexported so everyMoneyis valid by construction. Concepts: value objects, invariants, "make invalid states unrepresentable" (Day 130). -
cacheaside/— Implement the cache-aside read pattern:Getreturns a cached value on a live hit, otherwise calls the injectedLoader, populates with a TTL, and counts hits/misses;Invalidatedrops a key; expired entries reload; loader errors are NOT cached. An injectedClockmakes TTL expiry deterministic (no sleeping in tests). Concepts: cache-aside, TTL/staleness, delete-on-write, injected clock (Day 132).
Results¶
| Exercise | Focus | go test |
|---|---|---|
ports |
hexagonal port + adapter + injected service | ✅ |
money |
value object / invariants / value equality | ✅ |
cacheaside |
cache-aside read-through, TTL, invalidation | ✅ |