Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Android App and Server, duplicate model objects

 
Kevin Myer
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, so I am working on an android application where some model objects (Item, Employee, etc...) are used on both the server side and app side.
Currently I have duplicate classes in each project for those objects, but there must be a better way...

Is there any "standard" way to handle this in android? My only thought is packaging those classes into a Jar which would then be used in both projects.


 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't really an 'android' issue so there isn't an android-specific solution - but the same problem can occur whenever you have two sides to the same application (web-client, peer-peer, etc...). But, yes, the solution you mention - breaking the model out into a separate library and using it as a resource for both sides of the application is the right thing to do. I tend to break down such applications into multiple different projects - data model, network connection management, control elements, UI, utilities..., and piecing the projects together to get the final applications. That way I can re-use the data model if needed, and the network manager if needed, and only have to write and test the code once. Then the Android specific UI stuff goes in a project, declares the others as dependencies, and is built to an app. The same for the Web application.

The trick (I think) is to break it into pieces - but not too small to avoid fragmentation, circular dependencies, and versioning requirements...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic