2014-01-30 45 views
0

QCM的結構將存儲像設計XML到OOP方式

qcm.xml -->master node 
    groups.xml -> list of groups 
     group.xml -> group node 
      questions.xml -> list of questions 
       question.xml -> question node 
        anwsers.xml -> list of answers. 
         anwser.xml -> answer node 

而對於每一個的QCM, GROUP, QUESTION, ANSWER將包括:

content.xml 
variant.xml 
property.xml 

Firts我可以說element是最小的一部分:

ELEMENT 
    +content 
    +property 
    +dataListRef 

XML內容:

1.1) groups.xml (list of groups::groupListRef) 

<groups> 
     <group id="123"></group> 
     <group id="345"></group> 
     <group id="567"></group> 
</groups> 
1.1.1) group.xml (group element) 
    <group> 
     <content id="123"></content> 
     <property id="123"></property> 
     <questionListRef id="123"></questionListRef> 
    </group> 
    1.1.1.1) questions.xml (list of questions::questionListRef) 
      <questions id="123"> 
        <question id="123"></question> 
        <question id="345"></question> 
        <question id="567"></question> 
      </questions>    
      1.1.1.1.1)question.xml (question element) 
        <question id="123"> 
         <content id="123"></content> 
         <property id="123"></property>  . 
         <answerListRef id="123"></answerListRef>  
        <question> 
        1.1.1.1.1.1) answers.xml (list of answers belong to question::answerListRef) 
          <answers id="123"> 
           <answer id="123"></answer> 
           <answer id="345"></answer> 
           <answer id="567"></answer> 
          <answers> 
           1.1.1.1.1.1.1) ... 



1) content.xml 
    <content id="123"> 
     <variant id="123"></variant> 
    <content> 
     a.1)variant.xml 
      <variant id="123"> 
       <text></text> 
       <image></image> 
       <table></table> 
       <file></file> 
      </variant> 
2) property.xml 
    <property id="123"> 
     <segment></segment> 
     <context></context> 
    </property> 

我的方式(我不擅長在空中接力):

<?php 
interface element { 
    public content //obj of content 
    public property //obj of property 
    public listRef //array of obj [123,321,253] 

} 
class content{ 
    //some property 
    //some property 
} 
class propery{ 
    //some property 
    //some property 
} 
class listRef { 
    //some property 
    //some property 
} 

class group implements element{ 
    //some property 
    //some property 
} 
class question implements element{ 
    //some property 
    //some property 
} 
class answer implements element{ 
    //some property 
    //some property 
} 
?> 

任何人可以提供一些指導原則來設計這種情況下,到面向對象的方法呢?

感謝

回答

1

更多或更少的類模型將是這樣的

abstract class Element { 
    int id; 
    public Content content;//obj of content 
    public Property property;//obj of property 


} 
class Content{ 
    int id; 
    Variant variant; 
} 
class Propery{ 
    int id; 
    String segment,context; 
} 

class Variant { 
    int id; 
    String text, image, table, file; 
    } 

    public class Qcm extends Element { 

     List<Group> groups = new ArrayList<Groups>();  


} 

public class Group extends Element { 

    List<Question> questions = new ArrayList<Question>();  


} 

public class Question extends Element { 

    List<Anwser> anwsers = new ArrayList<Anwser>();  


} 
public class Answer extends Element { 


} 

如果你不喜歡這樣,你必須進入一個元素得到任何孩子。例如,要訪問答案,您需要進入問題。如果你喜歡有獨立的一切,並在父領域只保留一個參考的孩子,你可以改變它按照這樣的邏輯:

public class Question extends Element { 

    int answerListRef; 


} 
SparseArray<ArrayList<Anwser>> answerLists = new SparseArray<ArrayList<Anwser>>(); 

這樣,而不是有問題的內部答案的列表,你有一個列表的外部列表,由他們的id索引。所以,如果你有一個問題,你可以通過訪問答案列表:

ArrayList<Anwser> anwersOfThisQuestion= answerLists.get(question.answerListRef); 
當然

,你可以決定是否讓所有領域的公衆,或使他們私人的,然後使用getter和setter方法進行訪問,像這樣:

public class Question extends Element { 

    private int answerListRef; 
    public void setAnswerListRef(int answerListRef){ 
     this.answerListRef=answerListRef; 
    } 

    public void getAnswerListRef(){ 
    return answerListRef; 
    } 



} 
+0

是的,請看看我的更新卡洛斯羅伯斯。謝謝 – kn3l