← Back to PatternPip

FACTORY METHOD / PRACTICE

Start a round.
Let its question vary.

You followed a vehicle from its creation hook back into dispatch(). Now build the same kind of boundary for quiz questions.

YOUR MISSION / QUIZ ROUNDS

Change the question.
Keep the round workflow.

A quiz framework gets a Question, calls ask(), then packages the prompt with the same heading and ten-point score. Math and science need different question objects.

Choose where creation belongs. Test both rounds, then add a word question through a new creator. As with delivery, setup selects the creator; its factory method creates the product.

01 / DESIGN THE CREATION BOUNDARY

Make three design choices.

Choose the product contract, decide where creation belongs, then wire up the caller.

What should the workflow receive?

Try your own design first. Hints and retries are unlimited.

02 / CREATE · RETURN · USE

One workflow. Different questions.

Local simulation

Start with math. Check that your workflow creates a question and returns its prompt with the common heading and score.

Predict first (optional): who chooses the question class in your design?
REQUESTED · Math round

Setup selects: Choose a round

SHARED WORKFLOW

QuizRound.start()

  1. 1Obtain a Question
  2. 2Call question.ask()
  3. 3Package the card
Heading + 10 points stay here.
createQuestion()
CONCRETE CREATOR

Choose a round

Setup will choose which round to instantiate.

createQuestion()Overrides creation only
PRODUCT · QUESTION OBJECT

No question object yet

The selected round exists first. A Question is created during the trace.

RETURNED TO CALLER

The finished quiz card appears after the workflow uses the question.

Choose all three pieces to unlock the trace.

Your choices drive this trace. Test both rounds to check the design.

Each trace starts a fresh round. Changing a design choice clears all verification.

See the code behind your design TypeScript

03 / EXTEND THE QUIZ

A word round joins the quiz.

It asks “What is the opposite of quiet?” and uses the same heading and ten-point score. Which edits add this round while preserving the shared workflow?

First finish passing Math and Science traces with the same assembly.

Select all required edits

Compare with a complete solution

No timer and no attempt limit. Use hints, retry, or reveal the answer whenever it helps.