有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Google AppEngine(Java)中的复杂类层次结构

在Google AppEngine for my entities(JDO)的Java(GAE/J)中,是否可能有多个类继承/扩展同一个类。 例如,我有:

  • Content (Abstract class)
  • Course

然后我的课程将有:

  • list of Video that is extends Content
  • list of Books

同时

  • Video has list of Tags
  • Book has list of Tags
  • Course has list of Tags

有可能做这件事吗

我正在做类似的事情,但是有很多问题。有这类东西的例子吗


共 (3) 个答案

  1. # 1 楼答案

    根据你提到的,我将在黑暗中拍摄:

    • 将标签列表与管理方法一起放入内容中
    • 视频、书籍和课程都可以扩展内容(不确定这在设计中是否有意义)
    • 课程可以包含视频和书籍的列表
    • 所有都将有标签列表

    正如我提到的,这在您的设计中可能没有逻辑意义,但是如果没有更多的信息,我就说不出来了

  2. # 2 楼答案

    根据新问题标题进行更新

    我还是不明白你有什么困难,但我会试试看

    你的问题是

    Is it possible to have multiple classes that inherit/extends same class in Google AppEngine with Java (GAE/J) for my entities

    答案是肯定的,为什么不呢?我看不出你的问题中有什么不能做的。你有什么问题

    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.

    为了帮助你,这里有一个方法

    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 
    } 
    
  3. # 3 楼答案

    似乎您提到的大多数类关系都应该是组合实例,而不是继承实例。在Java中不能实现多个实现继承,但可以实现多个接口。合成没有这些限制,一个对象可以包含对不同(多个)类的其他对象(合成)的引用