OOD & LLD Reference/Classic LLD: Resource & State Machines

Library Management System

Books, copies, members, reservations, fines — models catalog vs inventory separation and search/filter extensibility.

3/5Overview: 30m

Problem framing

Members borrow books, reserve unavailable titles, pay fines. Tests catalog/inventory split, loan lifecycle, and waitlist notification (Observer).

EntityResponsibility
BookCatalog record: title, ISBN, author (bibliographic)
BookItemPhysical copy: barcode, rack location, availability
MemberAccount, borrow limit, fine balance
LoanLinks member + bookItem + due date
ReservationQueue when no copy available
Library / LibraryFacadeOrchestrates search, lend, return, reserve

Catalog vs inventory

One Book (ISBN) maps to many BookItem copies. Search operates on catalog; lending operates on available items. This mirrors Fowler's Catalog vs Inventory — never conflate "Harry Potter exists" with "copy #47 is on shelf 3."

Key flows

Lend — find available BookItem for ISBN → create Loan → mark item unavailable. Reserve — if no copy, add Reservation to queue. Return — close loan, compute fine if overdue, mark available, notify first reserver (Observer or explicit ReservationService.notifyNext()).

Search extensibility

SearchCriteria (author, title, ISBN) with BookCatalog.search(criteria) — new filters add criteria fields or a Strategy, not edits to every caller. Keeps catalog queries OCP-compliant.

Senior-level signal

Model fines in a FineCalculator strategy (flat daily rate vs grace period). State M:N explicitly: one member, many loans; one book, many items. Defer: full-text search, multi-branch libraries, concurrent holds — name them as extensions.

Where this goes next

Elevator System combines state machines with scheduling Strategy — multiple actors competing for a shared resource, like parking spots but with temporal ordering.

Further Reading

Practice Tasks (Optional)

Design or implement locally in any language — no autograding. Focus on class structure, extensibility, and being able to explain trade-offs out loud.

  • Design lend and reserve flows

    Model Book (title, ISBN), BookItem (barcode, copy), Member, Loan, Reservation. Walk through: member reserves unavailable book → book returned → member notified. 6–8 classes.

    40m