开发者

DAO Best practices : Querying Parent / Children

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 autho开发者_如何学编程r);
}

or

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜