Skip to content

Commit

Permalink
Refactor listBooks method
Browse files Browse the repository at this point in the history
Extract instance variable from local variable in listBooks method
and eliminate duplicated code by adding initializeBooks.
  • Loading branch information
guilhermedias committed Jul 31, 2015
1 parent 5d4c50e commit 9f6bce9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/com/twu/biblioteca/Biblioteca.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ public class Biblioteca {
List<Book> books = new ArrayList<Book>();

public Biblioteca() {
initialiazeBookList();
}

public Biblioteca(String welcomeMessage) {

this.welcomeMessage = welcomeMessage;
initialiazeBookList();
}

public String welcomeUser() {
return welcomeMessage;
}

public List<Book> listBooks() {
List<Book> bookList = new ArrayList<Book>();
return books;
}

private void initialiazeBookList() {
Book book = new Book("Harry Potter");
bookList.add(book);
return bookList;
books.add(book);
}
}
4 changes: 4 additions & 0 deletions src/com/twu/biblioteca/BibliotecaApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ public class BibliotecaApp {
public static void main(String[] args) {
Biblioteca biblioteca = new Biblioteca();
System.out.println(biblioteca.welcomeUser());

for(Book book : biblioteca.listBooks()) {
System.out.println(book.name + "\n");
}
}
}

0 comments on commit 9f6bce9

Please sign in to comment.