私は(最終的に)私がそれが動作するように質問フォームを作ることができました。最後の部分はまだ失われています:質問が属するカテゴリ。質問の永続化を管理する質問ハンドラクラスを作成しました。クラスの他のメソッドと一緒に入れるべきかどうか疑問です。すべてのカテゴリを抽出して表示できるようにするコードはどこに置くべきですか?
10のカテゴリ(IDと説明のみ)があります。私はどのように整理すべきか、裏付豆に属するものを正確に知るための経験と知識が不足していると思う。
public abstract class QuestionHandler {
@Inject
protected QuestionServiceBean questionBean;
@Inject
protected Question question;
protected List<Answer> answers;
protected List<Category> categories;
protected String correctAnswer;
public void updateQuestion() {
questionBean.updateQuestion(question);
}
public String persist() {
question.setAnswers(answers);
question.setCategories(categories);
questionBean.persistQuestion(question);
}
public void persistAsUserSubmitted() {
question.setAnswers(answers);
question.setCategories(categories);
questionBean.persistAsUserSubmitted(question);
}
protected void addAnswerAlternative() {
if (answers != null) {
answers.add(new Answer());
}
}
public abstract void init();
// Removed the getters/setters for readability.
}
このクラスは必然的に拡張され、initメソッドが実装されていますが、ここでは重要ではありません。
通常、servicebean prドメインモデルは1つありますか? (私は学んでいるので、それは多分愚かな質問です) – LuckyLuke
それは絶対に素晴らしいです。 – yatskevich