我有一个方法,在我的代码中使用3-4次,来自不同的位置。通常,我们会为此引入一个静态实用程序方法,我也是这样做的。
但是我想知道这是否是一个好的实践,如果这个静态方法执行某种数据库/数据逻辑?以以下为伪代码示例:
class DaoUtiliy {
public static void updateToDB(List a, List b) {
Dao dao = new Dao();
dao.open(); //begin transaction
//create some variables using the list a, that are used to fetch the db entry:
String time, String date; //some more
Entity entity = dao.find(time, date);
//update anything in that entity;
entity.setProperty(b.get(0));
dao.close(); //commit transaction
}
}你能把这个也放在静态的方法里吗?或者更确切地说,创建一个new DaoService().updateToDB(a, b); anc从需要它的地方调用这个方法?
发布于 2014-01-22 16:42:33
我喜欢DAO中的非静态方法,原因如下
https://stackoverflow.com/questions/21262961
复制相似问题