How to get inheritance to work in my model layer?
I know that you should extend Model
to get all the jpa functionality. However, java does not allow multiple inheritance... Therefore, I would like to know how to architect in play the following design:
public class Person extends Model {
}
// s开发者_StackOverflow中文版hould be able to extend Person
public class Doctor extends Model {
}
// should be able to extend Person
public class Patient extends Model {
}
public class Item extends Model {
// Doens't matter whether it's a Doctor or a Patient
@ManyToMany
public List<Person> owners;
}
Thanks in advance.
Your Doctor and Patient objects should inherit from Person. Java does not allow multiple inheritance but you can extend children objects with Person which inherits model already.
public class Person extends Model {
}
public class Doctor extends Person {
}
public class Patient extends Person{
}
public class Item extends Model {
@ManyToMany
public List owners;
}
What you cannot do in Java is:
public class Doctor extends Person, Model {
}
精彩评论