I am trying to follow Model-View-Controller practices for learning app development.
Right now I am having trouble figuring out how to balance between storing things in a database vs. a class in relation to viewing/processing.
For example my app lets you create profiles. I have a SQLite database that holds all the names in a table.
However this feels funny to me. For example if I want to populate a ListView with the profile names, I have to create an ArrayList<String>, populate it with the profile names from the database (via cursor), and then set it via ArrayAdapter<String>.
Maybe this is all fine and well, but it feels funny to me because I don't use something like a Profile class. Right now such a class would only hold a private String mProfileName and have some getters/setters, but is this class not needed if I already have the database storing everything?
I'm confused as to whether or not I should have a private ArrayList<String> mProfileNames member variable in my activity class, or if I should aim for a private ArrayList<Profile> mProfiles member variable in my activity class instead, or if it's not necessary to have such an arraylist in the first place since all that data is in the database so I only need to instantiate an arraylist in the function where I use it with the adapter/listview-setting, etc.
Because if I do have a private member variable holding all these names in addition to the database, then I have to worry about making sure that any time I update the database in any way (adding/removing/etc), I also update the arraylist in the same way, and this feels like a bad practice / risk for some reason.
Or maybe I use a Profile class to encapsulate the SQL functions instead of my activity?
I could really use some pointers in the right direction to properly implement MVC practice in this example.
Aucun commentaire:
Enregistrer un commentaire