Win a copy of Modern frontends with htmx this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Android App and Server, duplicate model objects

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic