开发者

Hibernate DAO method parameters

开发者 https://www.devze.com 2023-01-04 07:21 出处:网络
Which one do you prefe开发者_如何学编程r and why? Reservation[] find(User user, Show show) Reservation[] find(long userId, long showId)

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

精彩评论

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