← 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 BRIEF

New question types, one round workflow.

The framework starts a round, obtains a question, calls ask(), and packages the prompt with a common heading and ten-point score. Math and science rounds need different question objects.

Assemble a creation hook that lets each concrete round supply its question. Predict the next call and trace both rounds before extending the quiz with a word round.

Shared workflow
dispatch() → QuizRound.start()
Creation hook
createTransport() → createQuestion()
Concrete creator
RoadDelivery → MathRound
Created product
Truck → MathQuestion

The product contract

interface Question { ask(): string }

Keep the common workflow in the creator. Each subclass overrides creation; it does not copy the entire workflow.

01 / ASSEMBLE

Give the workflow a creation hook.

Choose a product contract, a shared workflow and which concrete round setup selects.

Inspect your full assembled code

Your assembled code

TypeScript preview. Highlighting follows the selected execution. The plain-string choice deliberately fails this workflow's ask() contract. In the branching version, creator subclasses are unused.

1. Products and card

// Choose a product contract.

2. Shared workflow

// Choose how the shared workflow gets a question.

3. Concrete creators

// Choose which concrete creator setup selects.

4. Setup and result

// Complete the workflow and creator pieces to wire a round.

02 / PREDICT & TRACE

Follow the question back to its creator.

Start a trace, predict the call at the creation boundary, then follow the object back into the workflow. Each step waits for you.

Choose all three pieces in step 1 to unlock the creation trace.

Expected prompt: What is 2 + 3?

Who creates the question?

Your trace will show the selected workflow, creation decision and resulting object together. Assemble the pieces above, then start.

  • ○ Math round — finish a passing trace to verify
  • ○ Science round — finish a passing trace to verify

This replays a local run of your selected assembly. Excerpts omit recording callbacks.

03 / TRANSFER THE IDEA

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.