Design a Bookstore system with books organized by genre
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2021-06-10
Problem Statement
Design a Bookstore system where books are organized by genre. The focus is on object-oriented design, modularity, and efficient management of books, genres, and customer interactions.
✅ Functional Requirements
1.Book Management
•Store book information: id, title, author, genre, price, availability.
•Add, remove, or update book details.
•Organize books by genre for easy retrieval.
2.Genre Management
•Maintain a catalog of genres.
•Support adding, removing, and querying genres.
•Each genre can have multiple books.
3.Customer Management
•Customers can search for books by title, author, or genre.
•Customers can view book details and availability.
4.Purchase / Inventory Management
•Customers can purchase books.
•Reduce stock quantity upon purchase.
•Track inventory for restocking purposes.
5.Optional Features
•Recommendations based on genre.
•Wishlist or cart functionality.
🔐 Constraints & Assumptions
•Focus is on LLD and object-oriented design, not payment gateway integration.
•Stock quantity is updated immediately upon purchase.
•Assume in-memory or database-backed storage for simplicity.
•The system should allow efficient retrieval of books by genre.
🧱 Key Components & Classes
1.Book Class
1
2class Book {
3private:
4 int bookId;
5 string title;
6 string author;
7 string genre;
8 double price;
9 int quantity;
10public:
11 void updateStock(int qty);
12 string getGenre();
13};1.Genre Class
1
2class Genre {
3private:
4 string name;
5 vector<Book*> books;
6public:
7 void addBook(Book* book);
8 void removeBook(Book* book);
9 vector<Book*> getBooks();
10};1.Customer Class
1
2class Customer {
3private:
4 int customerId;
5 string name;
6 string email;
7public:
8 vector<Book*> searchByTitle(string title);
9 vector<Book*> searchByAuthor(string author);
10 vector<Book*> searchByGenre(string genre);
11};1.Bookstore Class
1
2class Bookstore {
3private:
4 unordered_map<string, Genre*> genres; // genreName -> Genre
5 unordered_map<int, Book*> books; // bookId -> Book
6public:
7 void addBook(Book* book);
8 void removeBook(int bookId);
9 void addGenre(string genreName);
10 vector<Book*> getBooksByGenre(string genreName);
11 bool purchaseBook(int bookId, int quantity);
12};🔄 Example Workflow
1.Admin adds a new book: addBook(book).
2.Book is associated with its genre.
3.Customer searches for books by genre: getBooksByGenre("Science Fiction").
4.Customer purchases a book: purchaseBook(bookId, quantity) → stock updated.
🧪 Expected Deliverables
•Class diagram showing Book, Genre, Customer, and Bookstore.
•Implementation of CRUD operations, search, and purchase logic.
•Test cases:
•Adding/removing books and genres
•Searching by title, author, and genre
•Purchasing books and updating inventory
•Handling edge cases (out-of-stock, invalid bookId)
💡 Discussion Points
•Trade-offs between unordered_map vs list for storing books per genre.
•Extensibility for recommendation engine or promotions.
•Handling large inventory efficiently.
•Optional: support multiple copies, editions, or digital books.