Design a library management system. What are the key classes?
Fast recall
Quick revision
Core answer
Can you identify core domain entities and distinguish between catalog abstraction (Book) versus physical instances (BookItem) in inventory management
Freshers often collapse Book and BookItem into one class, missing that one book title can have multiple physical copies with independent states
Explain the one-to-many relationship between Book and BookItem and mention how BookItem tracks location (shelf number) and condition separately
Interview-ready guide
Interview answer
I'd lead with the single most important modelling decision, because it's where most people slip: separating Book from BookItem. A Book is the catalog entry — title, author, ISBN — and there's exactly one per title. A BookItem is a single physical copy with its own barcode and an availability status. So the library has one Book record for Clean Code but maybe five BookItems on the shelf. A member borrows a BookItem, never the abstract Book, because you can only physically check out a copy.
From there the other classes follow naturally. Member and Librarian are the users, with Librarian having extra permissions. BookLending represents an active checkout, capturing the item, the member, the issue date, and the due date. Reservation is a hold on a title, and Fine is an overdue charge. The relationships are a Book having many BookItems by composition, and a Member having many active loans.
I'd put borrowing rules on the Member — a canBorrow method that checks they have no outstanding fines and haven't hit the loan limit. For behaviour, I'd mention I'd use Strategy for search and fine calculation so those can vary, and Observer so that when a copy is returned, the next member in the reservation queue gets notified. The big mistake to avoid is collapsing Book and BookItem into one class, because then you simply can't represent multiple copies or know which one is checked out.
Design a library management system. What are the key classes
Direct Answer
A library management system needs entities for catalog (Book), physical inventory (BookItem), users (Member, Librarian), and transactions (BookLending, Reservation, Fine). The key distinction is Book represents the catalog entry while BookItem represents each physical copy with its own barcode and availability status.
Deep Dive & Architecture
Book title and physical-copy identities
Book represents the catalogue record: ISBN, title, authors, and subject. BookCopy represents one barcode that can be available, reserved, loaned, lost, or under repair. A library may own five copies of one title, so borrowing a Book directly loses the state of each copy.
Loans and reservations record changing relationships
Loan connects one member to one copy and stores issue, due, and return dates. Reservation connects a member to a title or copy, records queue order and expiry, and has its own status. Member owns identity and eligibility rules; Librarian performs privileged catalogue or account actions.
Services coordinate use cases
Catalog handles search. BorrowingService checks eligibility, claims a copy, and creates the loan. FinePolicy calculates any overdue charge, while NotificationService sends hold or due-date messages. For example, returning barcode C-17 closes its loan, then either marks C-17 available or holds it for the next valid reservation. This split keeps catalogue facts, copy state, and transaction history distinct.
Code Example
enum BookStatus { AVAILABLE, LOANED, RESERVED, LOST }
class Book { // catalog entry (one per title)
private final String isbn;
private final String title;
private final String author;
private final List<BookItem> copies = new ArrayList<>(); // 1 -> many
}
class BookItem { // one physical copy
private final String barcode;
private BookStatus status = BookStatus.AVAILABLE;
boolean isAvailable() { return status == BookStatus.AVAILABLE; }
}
class Member {
private final String memberId;
private final List<BookLending> activeLoans = new ArrayList<>();
private double outstandingFine = 0;
boolean canBorrow() { return outstandingFine == 0 && activeLoans.size() < 5; }
}
record BookLending(BookItem item, Member member, LocalDate issued, LocalDate due) {}
A Member borrows a BookItem, not a Book — you can only check out a physical copy.
Common Mistakes & Pitfalls
- Merging Book and BookItem — then you can't track which physical copy is out, or have 5 copies of one title.
- Borrowing a
Book— you borrow aBookItem; the catalog entry isn't checkout-able. - A God
Libraryclass doing search, lending, and fines — split by responsibility (SRP). - No member borrowing rules —
canBorrow()should gate on outstanding fines and loan count.
Check your understanding
Answer these without looking back at the article.
- How do you handle the book reservation system in LLD?
- How do you model search functionality in the library system?
- How do you handle fines in the library management system?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.