Answer the question
In order to leave comments, you need to log in
Android. How to combine ORM model and OOP model?
There is an OOP class model that the application works with, for example
class User {
String name;
String password;
}
class User {
String responseStatus;
String name;
String password;
}
class User {
@DatabaseField (autoincrement = true) int id;
@DatabaseField String name;
@DatabaseField String password;
}
[
int id (for ORM) ;
String responseStatus (for REST) ;
String name (for OOP) ;
String password (for OOP) ;
]
? Answer the question
In order to leave comments, you need to log in
It's not worth putting everything in one class. The classes that you use for REST declare as dto objects, they must change synchronously both on the client and on the server. For communication between what is in the rest and what is in the database - write the simplest converters at the service level.
UPD
Simplest example:
dto class :
class User {
String responseStatus;
String name;
String password;
public User(final String responseStatus, final String name, final String password){
this.responseStatus=responseStatus;
this.name = name;
this.password=password;
}
//setters
//getters
}
class UserEntity {
@DatabaseField (autoincrement = true) int id;
@DatabaseField String name;
@DatabaseField String password;
//getters
//setters
}
public class UserService(){
//some field
public void addUser(final User user){
//some code
UserEntity userEntity = convert(user);
//save userEntity into db
}
private UserEntity convert(final User user){
//some if
//some logger
UserEntity userEntity = new UserEntity();
userEntity.setName(user.getName());
userEntity.setPassword(user.gerPassword());
return userEntity;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question