views:

544

answers:

4

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?

+1  A: 

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 
}
hhafez
oh, sorry, my bad. I mean Complex Hierarchy. I just changed my question title
Maksim
+2  A: 

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.

AdamC
+1  A: 

Are you using JDO or JPA inside App Engine?

R. Kettelerij
I'm using JDO for my application
Maksim
+1  A: 

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.

BenM