I really like the idea of active record and Im going to implement the following design:
All concrete models extends abstract model, which have basic CRUD operations.
Here is the sample save function on model:
public void save(){
try {
getDao().createOrUpdate(this);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
and here is 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;
}
As you can see I have Model.class. Are there any other options or patterns to implement the following design, except passing a Class to getDao function?
Do not make
getDaomethod static and then:Edit:
In that case, you will have to somehow tell the getDao method what dao to get. You could use something like: