Modelling Case Studies
Case Study: A Library Lending System
Members, books, copies, loans and reservations — and why the difference between a book and a copy decides the whole design.
By the end of this chapter
- Separate a catalogue title from the physical copies of it
- Model a Loan as the object that relates a member to a copy over time
- Put rules that vary by member type behind a policy interface
The brief
A library lends physical books. Members search the catalogue, borrow copies, renew them and return them. If every copy of a title is out, a member can reserve it and is notified when one comes back. Late returns earn a fine. Payments, acquisitions and inter-library loans are out of scope.
- Assume a member may hold at most five loans at once; staff accounts may hold more.
- Assume a 14-day loan period and one renewal, refused if another member is waiting for the title.
- Assume fines are charged per day late and capped per loan.
- Assume a member with unpaid fines over a threshold cannot borrow.
Entities
Underlining nouns gives book, copy, member, loan, reservation, fine, catalogue. The single most important decision is splitting Book — the title, with an ISBN and an author — from BookCopy — one physical object with a barcode, a condition and a location. Members borrow copies and reserve books.
Before and after
Why the split matters
One Book class with a counter
Sign in to keep a note here. It is free, and nobody else can see it.
Sign inYou’ve reached the end
What this chapter was for:
- Book is the title; BookCopy is the thing on the shelf. Conflating them hides every interesting question.
- A relationship with its own dates and rules — a Loan — deserves to be an object.
- Fines and loan limits vary; put them behind policies and keep the lending flow stable.
- Reservations attach to the title, holds attach to a copy.