I usually tend to define the model layer of my apps using POJO\'s, such as Article, Comment, etc.
I was about to implement an AlphabetIndexer in the adapter of one o
One vote for entity objects (POJOs). Passing cursors around, especially to the UI layer, feels so wrong to me (whether or not the Android sdk kinda implies doing it that way). There are usually several ways to populate your UI, and I tend to avoid those that directly use cursors. For example, to populate my custom list views, I use a SimpleAdapter and give my collection objects the ability to return a representation of themselves as a List extends Map
for the SimpleAdapter's constructor.
I use a pattern where each table is wrapped by an entity object and has a provider class that handles my CRUD operations associated with that entity. Optionally if I need extended functionality for the collections, I wrap them too (ie. EntityItems extends ArrayList
) The provider has a base class that I pass a reference to a DbAdapter class that does the heavy lifting around the db.
The biggest reason, other than personal preference, is that I want to hide this kind of code as far away from my UI as possible:
String something = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_CONSTANT));
If I see that kind of code inline in the UI layer, I usually expect to see much worse lurking around the corner. Maybe I've just spent too much time in the corporate world working on big teams, but I favor readability unless there's a legit performance concern or if it's a small enough task where the expressiveness is just enterprisey overkill.