我正在使用Hibernate。它效果很好。但是,假设我有一个对应于只有getter和setter和toString的数据库表的类,方法相同。现在我想添加一些更多帮助用途的方法,例如,假设我想通过添加一些描述文本来获取creationdate,如下所示。休眠设计模式问题
public class Client {
private long id;
private Calendar creationDate;
protected String password;
public long getId() {
return id;
}
@SuppressWarnings("unused")
private void setId(long id) {
this.id = id;
}
public Calendar getCreationDate() {
return creationDate;
}
public void setCreationDate(Calendar creationDate) {
this.creationDate = creationDate;
}
..
.. some other getters and setters that corresponding to SQL columns
//Here I would like to have some help methods. Is it recommended to put it here?
public String getCreationDateInSecs() {
return "Date in secs: " + creationDate.getTimeInMillis * 1000;
}
}
问题是:我应该在哪里放置这种方法?
我应该将它与Value对象添加到同一个类中,还是应该将它放在其他位置?我想知道最好的做法,如果你知道我的意思=)
问候
欧凯,我不知道。谢谢,我会从现在开始=) – kungcc 2011-01-22 09:12:30
@James P.当然没有义务。这就是为什么我用“should”而不是“must”:) @kungcc - 你也可以在你以前的问题上做到这一点。 – Bozho 2011-01-22 09:29:26
不用担心Bozho。我只是添加到您的回复:) – 2011-01-23 16:55:47