Time for action - implementing a mutable book

The MutableBook implementation is straightforward. We'll put it in the following package: com.packtpub.felix.bookshelf.inventory.impl.mock.

public class MutableBookImpl implements MutableBook
{
private String isbn;
private String author;
private String title;
private String category;
private int rating;

The sole constructor takes an ISBN as the parameter; it's the Book's mandatory attribute:

public MutableBookImpl(String isbn)
{
setISBN(isbn);
}

Then we implement the setters and getters. I'll show the first and then you can carry on with the others.

public void setISBN(String isbn)
{
this.isbn = isbn;
}
public String getISBN()
{
return this.isbn;
}
// ...

The toString() method returns a string representation of this book for debug printing:

public String toString() {
StringBuffer buf = new StringBuffer();
buf.append(getCategory()).append(": ");
buf.append(getTitle()).append(" from ").append(getAuthor());
buf.append(" [").append(getRating()).append(']'),
return buf.toString();
}
}

Simple implementation: Let's move onto the BookInventory mock implementation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset