1

My company wants to publish a library for android, so that other people can integrate our content easily in their custom apps.

Now I am still very uncertain how I should provide the content. Right now I am using POJOs to provide the data in my project.

I was following the debate "POJOs vs. Cursors" which turned out in favor of Cursors. I also have seen an example where somebody stores the parsed resource in a SQLLite-DB and accesses it later through Cursors.

I know that Cursors have many advantages compared to POJOs. But would you like to mess with cursors when you need to implement a library? Some of you guys might have written such libs as well. What did you use and why?


How other libs are doing it...

Facebook seems to use POJOs:

Response format: The server response is a JSON string. The SDK provides a Util.parseJson() method to convert this to a JSONObject, whose fields and values can be inspected and accessed.

Community
  • 1
  • 1
OneWorld
  • 17,512
  • 21
  • 86
  • 136

1 Answers1

2

We used the Cursor approach in our last project, and found it quite cumbersome. Especially having to check whether there's actually something in the Cursor, iterating over it, finding the right indices for values, closing it properly.. not something I like to do over and over again. Especially the whole index stuff tends to break quite easily, especially since you can't define constants for it if you're actually making use of projections.

A good approach would probably be to use Cursor backed POJOs, at least when it comes to collections. That way the data could be read on demand. You still would have to find a sensible way to close the cursor then, though.

In case of single objects, I say to hell with projections and just dump everything it into a POJO.

Timo Ohr
  • 7,947
  • 2
  • 30
  • 20
  • What do you mean by "Cursor backed POJOs"? Are POJOs the facade of your Cursor based data management? I have seen cursors as "frontend" for POJOs, but not the opposite way. – OneWorld Nov 26 '10 at 14:45
  • @OneWorld I'm not sure if it's worth calling it POJO as it's not that *plain* anymore, but some people make a wrapper object around cursor which holds private `Cursor` member and has helper methods like `getId`, `getImageUrl` and etc. Inside, it would be either plain `get` or `get` + `switch` (or any kind of logic). – Pijusn Aug 21 '13 at 08:21