Design A Library Management System - Grokking The Object Oriented Design Interview
Topics covered
Design A Library Management System - Grokking The Object Oriented Design Interview
Topics covered
Search Course
Object-Oriented Design
and UML
Object-Oriented Basics
What is UML?
Class Diagram
Sequence diagram
Activity Diagrams
Design an ATM
1 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
Design a Library
Management System
• System Requirements
• Use case diagram
• Class diagram
• Activity diagrams
• Code
2 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
System
Requirements#
3 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
4 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
Use case
diagram#
We have three main actors in our
system:
• Add/Remove/Edit book: To
add, remove or modify a book
or book item.
• Search catalog: To search
books by title, author, subject or
publication date.
• Register new account/cancel
membership: To add a new
member or cancel the
membership of an existing
5 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
member.
• Check-out book: To borrow a
book from the library.
• Reserve book: To reserve a
book which is not currently
available.
• Renew a book: To reborrow an
already checked-out book.
• Return a book: To return a
book to the library which was
issued to a member.
Class diagram#
Here are the main classes of our
Library Management System:
6 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
7 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
8 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
UML conventions
<<interface>>
Name
Interface: Classes implement interfaces, denoted by Generalization.
method1()
ClassName
property_name: type Class: Every class can have properties and methods.
Abstract classes are identified by their Italic names.
method(): type
A B Generalization: A implements B.
Activity
diagrams#
Check-out a book: Any library
member or librarian can perform
this activity. Here are the set of steps
to check-out a book:
[no]
[yes]
9 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
[else]
[yes]
[no]
System updates the status of the book to 'Loaned' Show error message
10 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
[no]
Calculate fine
[yes]
[no]
11 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
Code#
Here is the code for the use cases
mentioned above:
1. Check-out a book,
2. Return a book, and
3. Renew a book.
Java Python
1 public enum BookFormat {
2 HARDCOVER,
3 PAPERBACK,
4 AUDIO_BOOK,
5 EBOOK,
6 NEWSPAPER,
7 MAGAZINE,
8 JOURNAL
}
12 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
9 }
10
11 public enum BookStatus {
12 AVAILABLE,
13 RESERVED,
14 LOANED,
15 LOST
16 }
17
18 public enum ReservationStatus{
19 WAITING,
20 PENDING,
21 CANCELED,
22 NONE
23 }
24
25 public enum AccountStatus{
26 ACTIVE,
27 CLOSED,
28 CANCELED,
29 BLACKLISTED,
30 NONE
31 }
Java Python
1 // For simplicity, we are not defining get
2 // assume that all class attributes are pr
3 // public getter methods and modified only
4
5 public abstract class Account {
6 private String id;
7 private String password;
8 private AccountStatus status;
9 private Person person;
10
11 public boolean resetPassword();
12 }
13
14 public class Librarian extends Account {
15 public boolean addBookItem(BookItem book
16
17 public boolean blockMember(Member member
18
19 public boolean unBlockMember(Member memb
20 }
21
13 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
21
22 public class Member extends Account {
23 private Date dateOfMembership;
24 private int totalBooksCheckedout;
25
26 public int getTotalBooksCheckedout();
27
28 public boolean reserveBookItem(BookItem
29
30 private void incrementTotalBooksCheckedo
31
BookReservation, BookLending,
and Fine: These classes represent a
book reservation, lending, and fine
collection, respectively.
Java Python
1 public class BookReservation {
2 private Date creationDate;
3 private ReservationStatus status;
4 private String bookItemBarcode;
5 private String memberId;
6
7 public static BookReservation fetchReser
8 }
9
10 public class BookLending {
11 private Date creationDate;
12 private Date dueDate;
13 private Date returnDate;
14 private String bookItemBarcode;
15 private String memberId;
16
17 public static boolean lendBook(String ba
18 public static BookLending fetchLendingDe
19 }
20
21 public class Fine {
22 private Date creationDate;
23 private double bookItemBarcode;
24 private String memberId;
25
26 public static void collectFine(String me
27 }
28
14 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
Java Python
1 public abstract class Book {
2 private String ISBN;
3 private String title;
4 private String subject;
5 private String publisher;
6 private String language;
7 private int numberOfPages;
8 private List<Author> authors;
9 }
10
11 public class BookItem extends Book {
12 private String barcode;
13 private boolean isReferenceOnly;
14 private Date borrowed;
15 private Date dueDate;
16 private double price;
17 private BookFormat format;
18 private BookStatus status;
19 private Date dateOfPurchase;
20 private Date publicationDate;
21 private Rack placedAt;
22
23 public boolean checkout(String memberId)
24 if(bookItem.getIsReferenceOnly()) {
25 ShowError("This book is Reference on
26 return false;
27 }
28 if(!BookLending.lendBook(this.getBarCo
29 return false;
30 }
31 this.updateBookItemStatus(BookStatus.L
Java Python
15 of 16 05/11/22, 10:52
Design a Library Management System - Grokking the ... https://www.educative.io/courses/grokking-the-object-...
1 public interface Search {
2 public List<Book> searchByTitle(String t
3 public List<Book> searchByAuthor(String
4 public List<Book> searchBySubject(String
5 public List<Book> searchByPubDate(Date p
6 }
7
8 public class Catalog implements Search {
9 private HashMap<String, List<Book>> book
10 private HashMap<String, List<Book>> book
11 private HashMap<String, List<Book>> book
12 private HashMap<String, List<Book>> book
13
14 public List<Book> searchByTitle(String q
15 // return all books containing the str
16 return bookTitles.get(query);
17 }
18
19 public List<Book> searchByAuthor(String
20 // return all books containing the str
21 return bookAuthors.get(query);
22 }
23 }
Back Next
Report an Issue
16 of 16 05/11/22, 10:52