← Back to PatternPip

BUILDER / PRACTICE

One meal.
Built one choice at a time.

You met Builder while creating reports. Now apply it to a meal-ordering flow.

YOUR MISSION / MEAL ORDERS

Keep the choices.
Protect the finished meal.

A customer chooses a base, a main, then optional toppings. Keep the draft between steps, reject an incomplete build, and return meals that survive later edits.

An ordinary constructor is enough when all choices arrive at once. Here, a draft grows over several steps before a deliberate build boundary. Finally, reuse those steps in a lunch recipe.

01 / DESIGN THE BUILDER

Make three design choices.

Keep a draft, define the build boundary, and decide what a finished meal owns.

How do choices survive the next step?

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

02 / PREDICT · BUILD · COMPARE

A draft grows. A meal stays finished.

Local simulation

Build Rice + Tofu with Sesame. The finished meal should contain all three choices.

Predict first (optional): Before build(), is there a finished meal?

ONE BUILDER / CHOICES ACCUMULATE

No product yet
Builder · editable draft
Base
Not chosen
Main
Not chosen
Toppings
None
build()Your validation choice goes hereYour product ownership choice goes here
Meal 1 · returned to caller

Waiting for build()

Step through your design, or play and pause. Predictions are optional.

Your choices drive the result. Start a trace to test them.

Each test uses a fresh builder. The reuse test keeps one builder for both meals. Changing a design choice clears all verification.

See the code behind your design TypeScript

03 / TRANSFER THE IDEA

The same lunch, ordered again.

A popular lunch always uses Rice, Beans, Corn and Chili. Add a reusable recipe so callers do not repeat the construction steps.

This recipe plays the optional Director role: it coordinates existing steps. The builder still owns the draft, validation and product creation.

Choose the two required edits, then apply the recipe and follow its construction trace to finish.

First pass all three test cases with the same assembly.

Select all required edits

0 of 2 edits selected

Compare with a complete solution

No timer and no attempt limit. Try another assembly, use a hint, or reveal the answer when it helps.