Reputation: 1125
Related to this question on JPA and Android, but looking for design guidance.
I have some data which will be persisted with Objectify on AppEngine. These objects also need to be interacted with on an Android App (and later, an iPhone App). Let's say they are playing cards:
@Entity public class Card { @Id Long id; String suit; String value; }
Should I use the exact same class in my Android App as I do in AppEngine, or should I restrict these objects only to the layer closest to the DataStore, and re-encapsulate the data for transmission and use on the mobile - or use a superclass or Interface perhaps?
Upvotes: 1
Views: 410
Reputation: 320
Objects persisted thru Objectify have relationships that you may not want to drag with to the client.
Design of API interface (contract) sooner or later will require objects that are different than entity objects. I created two packages, one for Objectify entity and another for api with POJOs and endpoints
Upvotes: 0
Reputation: 8816
I suggest that you take the later approach since that will help you build a rich Domain model that is a set of pure classes and not interconnected with any other framework.
One can also refer to these classes as Data Transfer Objects or Value Objects. The nomenclature could be different but the principle is the same i.e. you want data to be passed between different layers of your applications.
Taking this approach of separation will help you a rich Domain model over time and it can be independent of underlying layers and the frameworks that they may use.
Upvotes: 4