Skip to content

Instantly share code, notes, and snippets.

@mbrowne
Created March 18, 2013 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrowne/5185113 to your computer and use it in GitHub Desktop.
Save mbrowne/5185113 to your computer and use it in GitHub Desktop.
DCI Quiz Example
class FreeResponseQuizContext
{
protected IEnumerable<Question> questions;
FreeResponseQuizContext(Student student, QuizTemplate quizTemplate) {
IEnumerable<QuestionTemplate> questionTemplates = quizTemplate.getQuestionTemplates();
QuestionGenerator = questionTemplates;
AnswerCalculator = questionTemplates;
Student = student;
}
role QuestionGenerator {
IEnumerable<Question> generate() {
IEnumerable<QuestionTemplate> list = ((IEnumerable<QuestionTemplate>)self);
foreach (var questionTemplate in list) {
//add each parsed question to the 'questions' context property
//we're storing questions as a property of the context since we'll need them again
}
//return list of questions ready to display to the user
return questions;
}
}
role AnswerCalculator {
//similar idea to QuestionGenerator; loop through questions, calculate answer for each,
//and return the answers
IDictionary<Question, Answer> calculateAndReturn() {
...
}
}
role ScoreCalculator {
...
}
role Student {
//might not need this, it's just an idea
void answerQuestions() {
...
}
}
interaction IEnumerable<Question> generateQuestions() {
return QuestionGenerator.generate();
}
interaction IDictionary<Question, Answer> calculateAnswers() {
return AnswerCalculator.calculateAndReturn();
}
//How well did the student do?
interaction int calculateScore() {
return ScoreCalculator.calculate();
}
}
class MultipleChoiceQuizContext
{
MultipleChoiceQuizContext(Student student, QuizTemplate quizTemplate) {
...
}
role MultipleChoiceGenerator {
...
}
interaction IDictionary<Question, IEnumerable<Answer>> generateQuestionsAndChoices() {
//How to use QuestionGenerator?
//Need to use it in conjunction with MultipleChoiceGenerator
...
}
interaction int calculateScore() {
//How to use ScoreCalculator?
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment