Experimentation - Would Like Feedback
-
In the past, I had honestly never really been too great with inheritance and such. I've used interfaces before but never "properly" I guess you would say. So today, in order to grasp the concept a little more, I decided to experiment with it a bit. I created a Class Library with components I can use to create the structure of a "quiz." The project is simply called "QuizLib." Now, the functionality works just as I had planned. But I would like to know if I went about it the correct way: Interfaces IQuiz - Quiz interface; contains information about the quiz (title, subtitle, etc.) * string Title; - The title of the quiz * string SubTitle; - The subtitle of the quiz * List Questions; - A collection of questions which are part of the quiz * void AddQuestion(IQuestion question); * void RemoveQuestion(IQuestion question); IQuestion - Question interface; contains information about questions which are part of the quiz (IQuiz) * string QuestionText; - The text for the question (e.g. Is CodeProject.com the best?!) * int Points; - The amount of points the question is worth IAnswer - Answer interface; contains information about an individual answer for an IQuestion * string AnswerText; - The answer's text (what will be displayed when you render the question with answers - e.g. "Yes", e.g. "No") * bool IsCorrect; - Is the answer a correct answer (this is only used in Multiple Choice questions and True/False questions) And then I have 2 classes which implement the IQuestion interface. And I have 2 classes which implement the IAnswer interface. class MultipleChoiceQuestion : IQuestion ...... class TrueFalseQuestion : IQuestion class MultipleChoiceAnswer : IAnswer ...... class TrueFalseAnswer : IAnswer For MultipleChoiceQuestion, there is no limit on how many answers the question can have. The MultipleChoiceQuestion class adds a "HasOneAnswer" field, which determines whether or not only ONE answer can be correct, or if the user must select more than one in order to correctly answer the question. For TrueFalseQuestion, the List field is auto-generated by the class, since "True" and "False" are the only 2 options. I hope this makes sense to everyone. Haha. I'm just
-
In the past, I had honestly never really been too great with inheritance and such. I've used interfaces before but never "properly" I guess you would say. So today, in order to grasp the concept a little more, I decided to experiment with it a bit. I created a Class Library with components I can use to create the structure of a "quiz." The project is simply called "QuizLib." Now, the functionality works just as I had planned. But I would like to know if I went about it the correct way: Interfaces IQuiz - Quiz interface; contains information about the quiz (title, subtitle, etc.) * string Title; - The title of the quiz * string SubTitle; - The subtitle of the quiz * List Questions; - A collection of questions which are part of the quiz * void AddQuestion(IQuestion question); * void RemoveQuestion(IQuestion question); IQuestion - Question interface; contains information about questions which are part of the quiz (IQuiz) * string QuestionText; - The text for the question (e.g. Is CodeProject.com the best?!) * int Points; - The amount of points the question is worth IAnswer - Answer interface; contains information about an individual answer for an IQuestion * string AnswerText; - The answer's text (what will be displayed when you render the question with answers - e.g. "Yes", e.g. "No") * bool IsCorrect; - Is the answer a correct answer (this is only used in Multiple Choice questions and True/False questions) And then I have 2 classes which implement the IQuestion interface. And I have 2 classes which implement the IAnswer interface. class MultipleChoiceQuestion : IQuestion ...... class TrueFalseQuestion : IQuestion class MultipleChoiceAnswer : IAnswer ...... class TrueFalseAnswer : IAnswer For MultipleChoiceQuestion, there is no limit on how many answers the question can have. The MultipleChoiceQuestion class adds a "HasOneAnswer" field, which determines whether or not only ONE answer can be correct, or if the user must select more than one in order to correctly answer the question. For TrueFalseQuestion, the List field is auto-generated by the class, since "True" and "False" are the only 2 options. I hope this makes sense to everyone. Haha. I'm just
Seems silly to split up IQuestion and IAnswer. You're never going to have a MultipleChoiceQuestion paired up to a TrueFalseAnswer for example, so that should be a single object IMO. An IQuestion+Answer type object. Even if you kept your design, I see no way of actually mapping a question to an answer.
-
In the past, I had honestly never really been too great with inheritance and such. I've used interfaces before but never "properly" I guess you would say. So today, in order to grasp the concept a little more, I decided to experiment with it a bit. I created a Class Library with components I can use to create the structure of a "quiz." The project is simply called "QuizLib." Now, the functionality works just as I had planned. But I would like to know if I went about it the correct way: Interfaces IQuiz - Quiz interface; contains information about the quiz (title, subtitle, etc.) * string Title; - The title of the quiz * string SubTitle; - The subtitle of the quiz * List Questions; - A collection of questions which are part of the quiz * void AddQuestion(IQuestion question); * void RemoveQuestion(IQuestion question); IQuestion - Question interface; contains information about questions which are part of the quiz (IQuiz) * string QuestionText; - The text for the question (e.g. Is CodeProject.com the best?!) * int Points; - The amount of points the question is worth IAnswer - Answer interface; contains information about an individual answer for an IQuestion * string AnswerText; - The answer's text (what will be displayed when you render the question with answers - e.g. "Yes", e.g. "No") * bool IsCorrect; - Is the answer a correct answer (this is only used in Multiple Choice questions and True/False questions) And then I have 2 classes which implement the IQuestion interface. And I have 2 classes which implement the IAnswer interface. class MultipleChoiceQuestion : IQuestion ...... class TrueFalseQuestion : IQuestion class MultipleChoiceAnswer : IAnswer ...... class TrueFalseAnswer : IAnswer For MultipleChoiceQuestion, there is no limit on how many answers the question can have. The MultipleChoiceQuestion class adds a "HasOneAnswer" field, which determines whether or not only ONE answer can be correct, or if the user must select more than one in order to correctly answer the question. For TrueFalseQuestion, the List field is auto-generated by the class, since "True" and "False" are the only 2 options. I hope this makes sense to everyone. Haha. I'm just
-
In the past, I had honestly never really been too great with inheritance and such. I've used interfaces before but never "properly" I guess you would say. So today, in order to grasp the concept a little more, I decided to experiment with it a bit. I created a Class Library with components I can use to create the structure of a "quiz." The project is simply called "QuizLib." Now, the functionality works just as I had planned. But I would like to know if I went about it the correct way: Interfaces IQuiz - Quiz interface; contains information about the quiz (title, subtitle, etc.) * string Title; - The title of the quiz * string SubTitle; - The subtitle of the quiz * List Questions; - A collection of questions which are part of the quiz * void AddQuestion(IQuestion question); * void RemoveQuestion(IQuestion question); IQuestion - Question interface; contains information about questions which are part of the quiz (IQuiz) * string QuestionText; - The text for the question (e.g. Is CodeProject.com the best?!) * int Points; - The amount of points the question is worth IAnswer - Answer interface; contains information about an individual answer for an IQuestion * string AnswerText; - The answer's text (what will be displayed when you render the question with answers - e.g. "Yes", e.g. "No") * bool IsCorrect; - Is the answer a correct answer (this is only used in Multiple Choice questions and True/False questions) And then I have 2 classes which implement the IQuestion interface. And I have 2 classes which implement the IAnswer interface. class MultipleChoiceQuestion : IQuestion ...... class TrueFalseQuestion : IQuestion class MultipleChoiceAnswer : IAnswer ...... class TrueFalseAnswer : IAnswer For MultipleChoiceQuestion, there is no limit on how many answers the question can have. The MultipleChoiceQuestion class adds a "HasOneAnswer" field, which determines whether or not only ONE answer can be correct, or if the user must select more than one in order to correctly answer the question. For TrueFalseQuestion, the List field is auto-generated by the class, since "True" and "False" are the only 2 options. I hope this makes sense to everyone. Haha. I'm just
Since
IQuiz
has methods to add/remove questions, itsQuestions
property should be aget
-onlyIEnumerable
ofIQuestion
objects instead of aList
. I would recommend separating the question/answer definitions (which are reference, read-only data) from a user's responses (which can be modified). Will reply with another post over the weekend. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
In the past, I had honestly never really been too great with inheritance and such. I've used interfaces before but never "properly" I guess you would say. So today, in order to grasp the concept a little more, I decided to experiment with it a bit. I created a Class Library with components I can use to create the structure of a "quiz." The project is simply called "QuizLib." Now, the functionality works just as I had planned. But I would like to know if I went about it the correct way: Interfaces IQuiz - Quiz interface; contains information about the quiz (title, subtitle, etc.) * string Title; - The title of the quiz * string SubTitle; - The subtitle of the quiz * List Questions; - A collection of questions which are part of the quiz * void AddQuestion(IQuestion question); * void RemoveQuestion(IQuestion question); IQuestion - Question interface; contains information about questions which are part of the quiz (IQuiz) * string QuestionText; - The text for the question (e.g. Is CodeProject.com the best?!) * int Points; - The amount of points the question is worth IAnswer - Answer interface; contains information about an individual answer for an IQuestion * string AnswerText; - The answer's text (what will be displayed when you render the question with answers - e.g. "Yes", e.g. "No") * bool IsCorrect; - Is the answer a correct answer (this is only used in Multiple Choice questions and True/False questions) And then I have 2 classes which implement the IQuestion interface. And I have 2 classes which implement the IAnswer interface. class MultipleChoiceQuestion : IQuestion ...... class TrueFalseQuestion : IQuestion class MultipleChoiceAnswer : IAnswer ...... class TrueFalseAnswer : IAnswer For MultipleChoiceQuestion, there is no limit on how many answers the question can have. The MultipleChoiceQuestion class adds a "HasOneAnswer" field, which determines whether or not only ONE answer can be correct, or if the user must select more than one in order to correctly answer the question. For TrueFalseQuestion, the List field is auto-generated by the class, since "True" and "False" are the only 2 options. I hope this makes sense to everyone. Haha. I'm just
To add to the previous answers, I would not use an interface for this - I would use an abstract class instead. The reasoning is that some of your logic will be common to all questions/answers in the form of the Questions enumeration (which should be a get only property returning a List as Ravi says) but it should return a copy of the questions list, not the list itself. Using an abstract class allows this to be in the base, an Interface doesn't so you have to rely on the implementor getting this right each time.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
To add to the previous answers, I would not use an interface for this - I would use an abstract class instead. The reasoning is that some of your logic will be common to all questions/answers in the form of the Questions enumeration (which should be a get only property returning a List as Ravi says) but it should return a copy of the questions list, not the list itself. Using an abstract class allows this to be in the base, an Interface doesn't so you have to rely on the implementor getting this right each time.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
I appreciate all the input. I will be taking this all into consideration as I go. It's just a learning project, nothing I planned to take anywhere. So this will all give me a fair amount of things I can learn in order to improve. Thanks!
djj55: Nice but may have a permission problem Pete O'Hanlon: He has my permission to run it.
-
I appreciate all the input. I will be taking this all into consideration as I go. It's just a learning project, nothing I planned to take anywhere. So this will all give me a fair amount of things I can learn in order to improve. Thanks!
djj55: Nice but may have a permission problem Pete O'Hanlon: He has my permission to run it.
You're welcome!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water