Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Experimentation - Would Like Feedback

Experimentation - Would Like Feedback

Scheduled Pinned Locked Moved C#
questioncombeta-testingoopcode-review
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matt U
    wrote on last edited by
    #1

    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

    S E R OriginalGriffO 4 Replies Last reply
    0
    • M Matt U

      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

      S Offline
      S Offline
      SledgeHammer01
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Matt U

        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

        E Offline
        E Offline
        ekolis
        wrote on last edited by
        #3

        I'd recommend using a generic

        List

        for the questions instead of a plain old List. That way you don't have to worry about casting the questions to IQuestion, or having someone add something that's not an IQuestion to the list!

        1 Reply Last reply
        0
        • M Matt U

          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

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          Since IQuiz has methods to add/remove questions, its Questions property should be a get-only IEnumerable of IQuestion objects instead of a List. 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. /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          1 Reply Last reply
          0
          • M Matt U

            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

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            M 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              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

              M Offline
              M Offline
              Matt U
              wrote on last edited by
              #6

              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.

              OriginalGriffO 1 Reply Last reply
              0
              • M Matt U

                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.

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                You're welcome!

                Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups