开发者

Hibernate DAO method parameters

Which one do you prefe开发者_如何学编程r and why?

  1. Reservation[] find(User user, Show show)
  2. Reservation[] find(long userId, long showId)

Thanks


If you have a free choice, with no constraints, then I'd always choose the first. In fact, I'd also return a Collection, such as a List rather than an array.

The reason is that using domain objects rather than ids keeps focus on the business side of things, rather than on the relational aspects.

An interface dealing only in domain objects is also easier to mock, since you don't have to suddenly fabricate ids.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜