• Post Reply Bookmark Topic Watch Topic
  • New Topic

OO design - Library  RSS feed

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I was trying to come up with the design for a library. Here are the requirements:

The library maintains a record of books and its members. It allows members to check out books. Books can be searched by author name or title. The books are classified into 4 categories - General, Sports, Politics, Business.

I've come up with this initial design:

Classes:

  • Category (enum)
  • Book
  • Member
  • Library


  • Category
    Attributes: SPORTS, GENERAL, POLITICS, BUSINESS

    Book
    Attributes: String title, String authorName, Category category, boolean checkedOut
    Methods: isCheckedOut(), getCategory(), getTitle(), getAuthorName(), checkOut(), return(), boolean equals(Object o), int hashCode()

    Member
    Attributes: String firstName, String lastName, String phoneNumber, List<Book> booksCheckedOut;
    Methods: getters for name and phone number, checkOut(Book book), return (Book book), boolean equals(Object o), int hashCode()

    Library
    Attributes: List<Member> members, Map<Category, isleNumber>, Map<authorName, List<Book>>, Map<title, List<Book>>
    Methods: List searchByauthorName(String authorName), List searchByTitle(String title), int getIsleNumber(Category category), checkOut(Member, Book), return(Member, Book)

    Kindly review and point out the flaws in my design. Also, please feel free to suggest changes to the requirements if I am missing something fundamental.

     
    Bartender
    Posts: 11445
    18
    Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How will you find out who has checked out a certain book? Check out date? Return date? Is it over due? Fine?
    Will your library have multiple copies of the same book?
    Can a book belong to multiple categories?
     
    Bartender
    Posts: 3271
    82
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You might want to add a unique identifier to your Book and Member classes.
    Books have an ISBN which is a unique identifying reference, people are a little harder (I used to know someone with the same name as his father and as they lived in the same house they had the same phone number - I guess with 'everyone' having mobile phones these days this makes this situation less likely) but adding a date of birth field can help. You probably should assign a unique number to each member ie their membership reference number.
     
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Prasanna Raman wrote:Kindly review and point out the flaws in my design. Also, please feel free to suggest changes to the requirements if I am missing something fundamental.

    Well, as Maneesh already said, you don't appear to have any scope for multiple copies of a Book. If you don't need it at this stage, that's fine; but it's probably worth thinking about.

    There's a few ways to tackle it: You could have a hierarchy like TitleBook, or you could just keep counts inside the Book class itself (eg: onShelf, onLoan, damaged, etc).
    If you go for the former, you'll need to come up with a way to uniquely identify each "copy" (in a real Library, this might well be done with a barcode), but your logic probably won't have to change much; if you decide on the latter, you'll probably need some mechanism for storing loan activity rather than just saying "this book is loaned out", because a "Book" won't be a single book any more.

    And if you want to get really fancy: a Book might also come in several forms - eg, hardback, paperback, audio, braille - but it's possibly a bit early to be worrying about that.

    Also: You've done a nice job of writing down your attributes and methods (well done), but you haven't indicated the method visibility.
    Take, for example, your checkOut() methods: do they all need to be public? I suspect not. It seems more likely to me that the Library one is likely to be the main port of call (but not necessarily), and that it will call the methods for the other classes - in which case, they can probably be made package-private.

    Keeping public methods to a minimum is quite important if you want to keep your design "clean".

    HIH

    Winston
     
    Prasanna Raman
    Ranch Hand
    Posts: 413
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you, Maneesh, Tony and Winston. Can I uniquely identify a book by having a barcode field, and then for multiple copies, I thought I could have a numberOfCopies field for each book. Will that work?

    Winston - yes, I am thinking that all methods in my library class would be public, and most methods in the Member and Book classes will be package-private; others will be private. Is this design reasonable or is it just absurd? checkOut() method in library is taking a member and a book as arguments. Is that OK?

    I am having checkOut method in all the classes. It seems reasonable to me, and I also couldn't think of other ways. Is this OK?

    To keep track of who has checked out what and see due dates etc., I think I can have a class (I am struggling to find a proper name for this class) which will have the receipt number (a unique number which the member gets upon check out), checkOutDate, dueDate and the list of books checked out under that receipt. I don't know if this is the best way to do it.
     
    Ranch Hand
    Posts: 221
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    A unique barcode identifier if probably the best way to go. It is the method in use at most libraries (at least those in the Cleveland, Ohio area libraries in which I was employed). It allows for multiple copies of a book instance. But don't forget to take into consideration how the book is shelved. Young Adult is labeled and shelved differently than childrens books, which are completely different from Adult Fiction and non-fiction.

    I understand the limitation on the number of categories, but it is a valid question/concern -- believe it or not books are generally categorized oddly. Bob Dylan is categorized under POP Music, of all things. Is a book on sports medicine categorized under sports, or medicine?

    One last thing that I didn't see -- are you accounting for multiple checkouts by a single member? If I am not mistaken, I currently have six books checked out from my local libraries.

    Sorry, didn't mean to ramble and some or all of this may not apply to your project.

    Regards,
    Robert
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!