Ask for the Book, Not the Shelf
Ask for the Book, Not the Shelf: Repository: Ask for the Book, Not the Shelf, Testing with Fakes: Why This Pays Off.
Updated
- Repository: Ask for the Book, Not the Shelf (Journeyman): When the checkout service talks to the database in the database's own words (tables, rows, columns, dates stored as text), every class that needs loans copies that code, tests need a database, and a new database means editing them all; a repository puts loans behind one interface in the app's own words, so a class asks for a loan and never learns where it's kept.
- Testing with Fakes: Why This Pays Off (Journeyman): Because the checkout service is handed its clock and its loan repository, a test can hand it a clock set to any day and loans kept in memory, so every late-fee rule and the five-book limit are checked in a few milliseconds, with no database and no waiting; this lesson writes those tests, names the kinds of stand-in (fakes, stubs and mocks), and says what they can't catch.