Complex Class Hierarchy in Google AppEngine (Java)
-
11-09-2019 - |
Question
Is it possible to have multiple classes that inherit/extends same class in Google AppEngine with Java (GAE/J) for my entities (JDO). For example I have:
- Content (Abstract class)
- Course
and then my Course will have :
- list of Video that is extends Content
- list of Books
At the same time
- Video has list of Tags
- Book has list of Tags
- Course has list of Tags
Is it possible to do it GAE?
I'm doing similar to this but having so much problems. Is there any examples of this kind of stuff?
Solution
Update based on new question title
I still don't understand what your difficulty is, but I will give it a shot
Your question is
Is it possible to have multiple classes that inherit/extends same class in Google AppEngine with Java (GAE/J) for my entities
The answer is yes, why not? I don't see anything in your question that can't be done. What problem are you having?
I'm doing similar to this but having so much problems. Is there any examples of this kind of stuff? How are you doing it exactly, because I can't see anything wrong with the description you posted.
and just to help you out, here is one way it can be done,
interface Tagable {
public doSomeThingWithTagList();
}
class abstract Content implements Tagable {
List<Tag> tagList;
}
class Video extend Content implements Tagable {
}
class Book Tagable{
List<Tag> tagList;
}
class Course Tagable {
List<Video> videoList;
List<Books> bookList;
List<Tag> tagList
}
OTHER TIPS
I'll take a shot in the dark here based on what you mentioned:
- Put the tag list in Content along with management methods
- Video, Books, and Course can all extend Content (not sure if this makes sense in the design)
- Course can contain List of Video and Books.
- All will have list of tags
Like I mentioned, this may not make logical sense in your design, but without more information, I can't tell.
It seems most of the class relationships you mention should be instances of composition rather than inheritance. You can't do multiple implementation inheritance in Java but you can implement multiple interfaces. Composition doesn't have these limits and an object can contain references to other objects (composition) of different (multiple) classes.