DAO recommendations: parent / child survey

Given that you have a domain model with simple relationships between parents and children, and each object has its own DAO, for example:

Author
AuthorDAO
Book
BookDAO

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

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

or

class BookDAO
{
    List<Book> getBooks(Author author)
}
+3
source share
2 answers

I would place the Bookfinder on BookDAO. I expect it to be, regardless of its parameters. If you want to find a book, you do not want to scan all the DAOs to find where the correct seeker is. Putting it in another place will not help API users.

+3
source

BookDAO, . Book .

+3

Source: https://habr.com/ru/post/1723337/


All Articles