Hibernate DAO 方法参数
您更喜欢哪一个,为什么?
- 预订[] find(User user, Show show)
- 预订[] find(long userId, long showId)
谢谢
Which one do you prefer and why?
- Reservation[] find(User user, Show show)
- Reservation[] find(long userId, long showId)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你有自由选择,没有任何限制,那么我总是选择第一个。事实上,我还会返回一个集合,例如列表而不是数组。
原因是使用域对象而不是 id 可以将重点放在事物的业务方面,而不是关系方面。
仅处理域对象的接口也更容易模拟,因为您不必突然伪造 id。
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.