views:

121

answers:

2

Hi

Given you have a domain model with a simple parent / child relationship, and each entity has it's own associated DAO, eg:

Author
AuthorDAO
Book
BookDAO

If I want to add a DAO method for retrieving the books by a specific author, what's the best place for it?

class AuthorDAO
{
    List<Book> getBooks(Author author);
}

or

class BookDAO
{
    List<Book> getBooks(Author author)
}
+1  A: 

The BookDAO, because you want to get information about books. The Book is the main subject here.

BalusC
+1  A: 

I'd place a Book finder on the BookDAO. This is where I would expect it to be, regardless of its parameters. If you want to find a book, you don't want to scan all DAOs to find where the right finder is. Putting it somewhere else won't help the users of the API.

Pascal Thivent