This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
When you borrow a book from the library or return a book to the library, it's an action you perform relative to a specific book; it makes no sense to return a book without referring to a specific book, right? The Library doesn't know which book you're returning or borrowing, which leaves it up to you, the borrower -- the person who calls the methods. So I think the methods of Library need to accept the book as a parameter:
The reason I need to do this is because later I have to evoke the method in a format like this firstLibrary.borrowBook("The Lord of the Rings").
Joined: May 15, 2009
Thanks for the information. I tried that and I am still getting "a non-static method cannot be referenced from a static context" error message. Also, how would I write those method if I have evoke the method for multiple books?
I thought about continuing EFH analogy about how you need an instance of library to borrow a book -- hence, you won't know where to borrow it from. etc. But...
Unless, you have an understanding of static and non-static context, and what is in scope during what context, you will keep get these error messages. So... I recommend that you go back and review the chapter on methods. You need to review the difference between static and non-static methods, and how, when do you use them.