Logic code reuse between apps for Android and other platforms: To ContentProvider or not to ContentProvider?

前端 未结 2 415
名媛妹妹
名媛妹妹 2020-12-21 03:40

I\'m developing an app which I want to make available both for Android and Blackberry (possibly to JavaME in the future). The business logic will be common to all the platfo

2条回答
  •  感情败类
    2020-12-21 04:00

    The business logic will be common to all the platforms - and hence, so will the corresponding layer in code.

    The vast majority of your code will be different between Android and your other versions. Blackberry and J2ME share a few dozen classes with Android, mostly in java.io and java.util. Even your "business logic" will need classes outside of the intersection of the three class libraries, most likely.

    Hence, I wouldn't worry one lick about trying to have a common code base. Common design, sure. Interchangeable data models, sure. Actual literal code, not worth worrying about, IMHO.

    Doesn't the functionality of the DataStore above (partially) overlap with that of the ContentProvider in Android?

    The APIs overlap in terms of actions. That's about it.

    The only reason I cannot entirely discard the ContentProviders is certain components of the Android system expect you to expose data as a ContentProvider (Search, for example).

    True, but in those cases, "the Android system" will not be supporting your data model, anyway. Search, for example, requires a fairly specific ContentProvider implementation, not just any old one.

提交回复
热议问题