QCM的结构将存储类似
的内容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
我可以说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>
我的方式(我不擅长oop):
<?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
}
?>
是否有人可以根据OOP方式提供一些指导方针来设计此案例?
由于
答案 0 :(得分: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;
}
}