Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Let say we have a server that manage a library in which you can add a book, find a book and get all the books. The server code will probably look like this (wink):

Code Block
java
java
titleBookService.groovy
class BookService {

  private List allBooks = new ArrayList()

  Book findBook(String isbn) {
    for (book in allBooks) {
      if (book.isbn == isbn) return book
    }
    return null
  }

  void addBook(Book book) {
    allBooks.add(book)
  }

  Book[] getBooks() {
    return (Book[])allBooks.toArray(new Book[allBooks.size()])
  }

}

...