DesignTheSystem/dev
EASY Low-Level Design (LLD) 13 automated tests

Design Library System (Low-Level Design)

Lend books to students and faculty with different limits, and charge fines for late returns. Focus: Policies that differ by member type.

DifficultyEASY
Design focusPolicies that differ by member type
Automated grading3 public + 10 hidden tests (13 total)
Phase 2 follow-upReservations
LanguageTypeScript (OOP / Machine Coding)

Problem statement

The library has books (by ISBN, with a number of copies) and members who are either STUDENT or FACULTY.

Students may hold 3 books at a time for 14 days; faculty may hold 10 books for 30 days. Days are whole numbers.

Returning late costs a fine per day late: students 10, faculty 5. A member with an unpaid fine cannot borrow until they pay it.

Functional requirements

  • addBook(isbn, title, copies) adds copies (adding an existing ISBN adds more copies).
  • addMember(id, name, kind) registers a member; borrow(memberId, isbn, day) lends a copy or throws (no copy, at the limit, unpaid fine, same book already held, unknown member or book).
  • returnBook(memberId, isbn, day) returns the fine for that book (0 if on time) and adds it to the member's unpaid fines.
  • fines(memberId), payFine(memberId), available(isbn) and borrowed(memberId) (ISBNs, in borrow order).

Required API & starter interface

Implement the TypeScript class interface below. You can add any helper classes, policies or strategies you need:

type MemberKind = "STUDENT" | "FACULTY";

class Library {
  addBook(isbn: string, title: string, copies: number): void {
    throw new Error("Not implemented");
  }

  addMember(id: string, name: string, kind: MemberKind): void {
    throw new Error("Not implemented");
  }

  borrow(memberId: string, isbn: string, day: number): void {
    throw new Error("Not implemented");
  }

  /** Returns the fine for this book */
  returnBook(memberId: string, isbn: string, day: number): number {
    throw new Error("Not implemented");
  }

  fines(memberId: string): number {
    throw new Error("Not implemented");
  }

  payFine(memberId: string): void {
    throw new Error("Not implemented");
  }

  available(isbn: string): number {
    throw new Error("Not implemented");
  }

  borrowed(memberId: string): string[] {
    throw new Error("Not implemented");
  }
}

Public test cases

Your code runs against 3 public tests plus 10 hidden edge-case tests in a sandbox:

Borrow and return on time (core)

var lib = new Library();
lib.addBook("111", "Clean Code", 1);
lib.addMember("s1", "Sam", "STUDENT");
lib.borrow("s1", "111", 0);
assertEqual(lib.available("111"), 0);
assertEqual(lib.returnBook("s1", "111", 14), 0);
assertEqual(lib.available("111"), 1);

Students pay 10 a day late (core)

var lib = new Library();
lib.addBook("111", "Clean Code", 1);
lib.addMember("s1", "Sam", "STUDENT");
lib.borrow("s1", "111", 0);
assertEqual(lib.returnBook("s1", "111", 17), 30);

No copy left (edge)

var lib = new Library();
lib.addBook("111", "Clean Code", 1);
lib.addMember("a", "A", "STUDENT"); lib.addMember("b", "B", "STUDENT");
lib.borrow("a", "111", 0);
assertThrows(function () { lib.borrow("b", "111", 0); });

Design & structure checks

Beyond passing tests, the grader inspects your class structure for clean object-oriented design:

  • Limits and fines come from a policy per member type, not if-statements on the kind: A third member type (staff, alumni) should mean adding one policy, not editing every method that checks the kind.

Phase 2: Change request

In real interviews, the follow-up tests whether your design is extensible. After your first version passes all 13 tests, you unlock the change request: Reservations.

Relevant low-level design lessons

More low-level design problems