Object-Oriented Design Interview: A Library Management System
3 views
"Design a library management system" is a common object-oriented design (OOD) or low-level design question for software engineering interviews. It tests class modeling, responsibilities, relationships, and handling rules like borrowing limits and fines. Here is a clean way to approach it.
1. Clarify requirements
Ask what the system must support. A typical scope:
- Members search the catalog by title, author, subject, or ISBN.
- Members borrow and return physical copies; each member has a borrowing limit (for example five items) and a loan period (for example 14 days).
- Members can reserve a book when all copies are out; the next returned copy is held for them.
- Late returns incur fines.
- Librarians add books and copies, manage members, and handle exceptions.
State what's out of scope, such as e-books or interlibrary loans, unless the interviewer wants them.
2. Identify the core classes
- Book: the title-level record (ISBN, title, authors, subjects, publication year).
- BookCopy (or BookItem): a physical copy with a barcode, status (available, loaned, reserved, lost), and shelf location. Separating Book from BookCopy is the key modeling insight interviewers look for.
- Member: account details, status, list of active loans, total fines.
- Librarian: staff user with extra permissions. Both can extend an Account or Person base class, or you can use roles instead of inheritance.
- Loan: links a member and a copy, with checkout date, due date, and return date.
- Reservation: member, book, created time, status (waiting, ready for pickup, fulfilled, expired).
- Fine: amount, related loan, paid status.
- Catalog: indexes for searching books.
- LibraryService (or a set of services): coordinates checkout, return, and reservations.
3. Key flows
Checkout: verify the member is active, has fewer loans than the limit, and owes no fines above a threshold; verify the copy is available or reserved for this member; create a Loan; update copy status.
Return: close the loan, compute any fine from days late times the daily rate, then check reservations for that book. If someone is waiting, mark the copy as reserved and notify them; otherwise mark it available.
Reserve: allowed only if no copy is available; add to a first-in, first-out queue per book.
4. Design choices worth explaining
- Use a policy object (LoanPolicy) for limits, loan periods, and fine rates so they can differ for students, staff, or children without changing core classes. This shows the Strategy pattern naturally.
- Notifications through an observer or event system decouple the library logic from email or SMS.
- Keep status changes inside methods on BookCopy and Loan rather than letting outside code set fields directly.
5. Concurrency
Two members trying to check out the last copy at once: the checkout must update the copy status atomically, using a lock or a database transaction.
6. Extensions
Renewals (disallowed if someone reserved the book), lost-item handling, multiple branches, and audit logs.
Staying structured
OOD interviews reward clear thinking more than perfect diagrams. Linkjob AI (https://linkjob.ai) provides real-time help during live job interviews and technical interviews, reminding you of flows or edge cases you haven't covered while you lead the design yourself.