• 1 Post
  • 61 Comments
Joined 1 year ago
cake
Cake day: July 1st, 2023

help-circle



  • “Is this a reasonable analogy”

    Kind of. That concept is sometimes referred to as the Factory Pattern. You give it some raw materials and it spits out some products.

    While in this question it does use a class, classes are more basic than that.

    I think of a Class like a blueprint for a car. And each car that is actually built from that blueprint as an Object. The blueprint can have settings, like paint colour, seat fabric and the like.

    For the question in the OP, you can imagine you design a form in Word that you print out. The form has 2 blank fields; Question and Answer. This is a Class. You can call it QuestionClass (terrible name, used for clarity)

    When you print those forms you are creating an Object. Also known as creating an Instance of the Class. Also known as Instantiating.
    Then you can fill in the questions and answers on each sheet/Object.

    You can, however, when designing your Class make it so you MUST supply the question and the answer for this instance when you create it, rather than add them later. You give the class some initial values. You call this an Initialiser.

    Now take a step back. Make a new function that takes in a list of Question-Answer pairs and spits out a bunch of the QuestionClass Objects.

    That’s a big chunk of the work done.