Bird
Raised Fist0

In designing a Library Management System, which component is best suited to handle the tracking of book loans and returns to ensure accurate availability status?

easy🔍 Pattern Recognition Q11 of Q15
OOP & Design Patterns - Design a Library Management System - LLD with Relationships & Edge Cases
In designing a Library Management System, which component is best suited to handle the tracking of book loans and returns to ensure accurate availability status?
AA separate LoanManager class that manages all loan and return transactions
BThe Library class, which maintains a global list of all books and their statuses
CThe User class, which tracks the books currently borrowed by the user
DThe Book class itself, by maintaining a status flag indicating availability
Step-by-Step Solution
  1. Step 1: Understand Single Responsibility Principle

    Tracking loans and returns involves managing transactions and state changes, which is best encapsulated in a dedicated LoanManager to avoid bloating Book or User classes.
  2. Step 2: Why not Book class?

    Embedding availability logic in Book violates SRP and complicates concurrency handling.
  3. Step 3: Why not User class?

    User should track borrowed books but not manage loan state transitions globally.
  4. Step 4: Why not Library class?

    Library manages collections but delegating loan logic to a specialized manager improves modularity and concurrency control.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    LoanManager centralizes loan logic, enabling better consistency and easier concurrency handling.
Quick Trick: Separate transaction logic from data entities for clarity and concurrency [OK]
Common Mistakes:
MISTAKES
  • Putting loan logic inside Book class
  • Letting User class handle global loan state
  • Overloading Library class with transaction details
Trap Explanation:
PITFALL
  • Options A, C, and B seem plausible because they relate to entities involved, but they mix responsibilities and complicate concurrency and state management.
Interviewer Note:
CONTEXT
  • Tests candidate's understanding of responsibility separation and component roles in LLD.
Master "Design a Library Management System - LLD with Relationships & Edge Cases" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes