【发布时间】:2013-05-13 18:00:07
【问题描述】:
我有一个类Lease 模拟类Customer 和VideoGame 之间的关系。非常简单明了;它看起来像这样:
class Lease() {
private VideoGame videoGame;
private Customer customer;
// etc.
public Lease(VideoGame videoGame, Customer customer) {
this.videoGame = videoGame;
this.customer = customer;
}
}
这三个类中的每一个都由具有自动生成索引的数据库表表示,另外leases 表还有一个外键来引用Customer 和VideoGame。
在从数据库中检索Lease 时,我应该...
- 继续在我的
getLease(long id)方法中检索VideoGame和Lease实例,并将这些对象存储在Lease实例中 -
或者,
Lease类只记住“外键”是否更好,我应该只在需要时才实际检索Customer和VideoGame的实例?这需要将Lease类更改为类租赁(){ 长视频游戏; 长期客户; // ETC。 }
first 方法似乎更自然,但我正在寻找一些“最佳实践”的建议。谢谢!
【问题讨论】:
标签: java relationship