I'm working on a project that is going to query a DB for exercises. The way it's currently going to be laid out is that you will come to a main window that has selection buttons for which type of exercise you want. Then that will bring up a list of exercises in that category. Finally, once a selection is made from the list it will bring up a detailed window showing an image (actually an animation) and text detailing how to perform the exercise. The user will be able to create new exercises if desired but the DB will be loaded with some standard exercises.
Anyway, I'm wondering if there is a best practice for something like this. I am not sure whether I should create all of the exercise objects first and store them in a list where the GUI can query them or if I should query them directly from the database and create a new object each time an exercise is selected.
I would think you would want to query the DB so it's less of a hassle to update the lists when a new exercise is added or an existing is edited. But at the same time I feel that may be wasted processing constantly querying the DB whereas I could just query the database in one big chunk and create all of the objects at once. Then if they edit or create an exercise I'll just append it to or edit the current list.
So, to sum it up, should I preload objects from a database, create new objects each time or both?
I'd suggest that you are indulging in what's known as "premature optimization" in the computer business. Don't spend a lot of time trying to guess how well two choices will perform. The best practice in this case is to write the simplest possible code and try it out. If it's too slow or if it uses up all of your memory, then you can start trying to improve it.