【发布时间】:2012-04-28 01:06:06
【问题描述】:
我真的很喜欢主动记录的想法,我将实现以下设计: 所有具体模型都扩展了抽象模型,抽象模型具有基本的 CRUD 操作。
这是模型上的示例保存功能:
public void save(){
try {
getDao().createOrUpdate(this);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这里是getDao():
private static Dao<Model, Integer> getDao(Context context){
Dao<Model, Integer> result = null;
DatabaseHelper dbHelper = new DatabaseHelper(context);
try {
result = dbHelper.getDao(Model.class);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
如您所见,我有 Model.class。除了将 Class 传递给 getDao 函数之外,是否还有其他选项或模式可以实现以下设计?
【问题讨论】: