I have data coming out of a SQLite database, normally, I grab an item from the DB and put it into my custom data Class “Invoice” which holds all of the particulars of an invoice. Within Invoice I have business logic to return things such as the Invoice’s balance (Sales Invoice will return the Invoice’s credit, Expense Invoice will return the Invoice’s debit) as well as other accounting specific quirks.
This being said, when I execute my SQL query and grab a cursor, chucking the cursor into a SimpleCursorAdapter and having my way with it doesn’t work as the business logic embedded into my Invoice class is bypassed. I’m thinking I am going to have to convert each cursor result into an Invoice object and then somehow list these objects in a ListView. Is this the most optimal way? Or, should I break convention and code the logic into my controller (the Class grabbing the cursor in the first place)?
I’d like to keep things as understandable as possible. This being said, I’d rather have a “purist” approach to this problem (e.g. keeping this object oriented within the MVC paradigm as much as possible) instead of hacking some logic together in the controller to do the logic.
What do you think? What would you do? One one hand using the “purist” approach definitely will take more processing power as it is less direct, however, would the maintainability and clarity of the code make up for this?
I appreciate your viewpoints!
If you use the plain
SimpleCursorAdapter. Instead, you could extendSimpleCursorAdapterand implement whatever logic you want in thebindView()method, but I guess you already know this(?!). Another option is to use the plainSimpleCursorAdapterand use aSimpleCursorAdapter.ViewBinderto bind the data where you need to do extra stuff that theSimpleCursorAdaptercan’t handle.Probably not.
If you build the
Invoiceclass(along with the extra stuff) only to display it to the user(in aListView) then I would drop building theInvoiceclass and implement whatever logic directly in theAdapter,ViewBinderetc(this probably isn’t the “purist” approach, but I think this is the most efficient way especially if the cursor with data will have like several hundreds rows).If you would use the
Invoceclass in other parts of your code also then I will probably pull the data from the cursor first.