Hibernate DAO method parameters
Which one do you prefe开发者_如何学编程r and why?
- Reservation[] find(User user, Show show)
- 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.
精彩评论