简体   繁体   中英

Android: What is the difference between the two sqlite approaches

I look at a tutorial here: http://www.chupamobile.com/tutorial-android/android-beginner-tutorial-part-66-creating-sqlite-databases-340

and then I see this tutorial here: http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

The first one does not create a class for the table while the second one does. What are the advantages of creating and using that table class and CRUD class?

I need to create an app that will use a fixed structure local database. 3 tables interconnected and mainly display cursors in listviews. I will load cursors into ListViews directly onClick of other listview items. (Categories, Subcategories, FinalItems)

Later I will implement an activity for updating the contents of the database from a remote MySQL server. But this information is just to help you get the big picture.

So for now I just want to know what road to take? Is it necessary to build classes for my tables and for the CRUD operations? Or is it enough to use the first tutorial?

Thank you

It is not "necessary" to create classes for your tables.

The reasons for creating such classes is to manage complexity. Your application sounds very simple, so such classes are likely unnecessary.

Large projects, become increasingly difficult to organize. At some point, it makes sense to move all of the code that talks to the database into either a single "Data Access Layer" class, or multiple classes (often one per table, but some tables just don't warrant a class).

My current project has to deal with a database containing just over 250 tables, as well as data coming in from web services. Finding every line of code that talks to table X would be nearly impossible if I didn't have them all grouped neatly into a single class.

It basically comes down to organization. The more complexity you are facing, the more organized you have to be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM