mardi 15 décembre 2015

Which class is right one for Db Queries?

I am writing an Android application that i need to store my contacts into SQLite database. Is it fine to write contact queries into contact model class? Or should i write another class for database connections for each model? Or should i write every database queries into the SQLiteOpenHelper class? What is the right approach for this problem?
Approach 1:

public class DatabaseHelper extends SQLiteOpenHelper {
    public static void addContact(Contact contact){
        //Db query here ?
    }
}

Approach 2:

public class Contact {
    private int id;
    private String name;
    private String surname;
    private String homeNumber, workNumber, mobileNumber;
    private String email;
    public static void addContact(Contact contact) {
        // db query in here ?
    }
}

Aucun commentaire:

Enregistrer un commentaire