01 / CALLERChooses the approach
Application setup
buildFooterReport()The caller creates a fresh ReportBuilder, chooses title, body and footer, then calls build(). No director is used.
Independent report jobs start with fresh builders.
Appearance
BUILDER / THE IDEA IN A MINUTE
Builder separates an object’s construction into explicit steps, so callers can assemble the parts they need before asking for the finished object.
The builder owns an unfinished draft. The product is the result. A caller chooses the steps; an optional director can coordinate a reusable sequence.
THE STRUCTURE / THREE CORE ROLES + AN OPTIONAL DIRECTOR
The caller asks a ReportBuilder to add parts. The builder owns the unfinished work; build() validates it and returns a separate Report. A reusable recipe can choose the steps for the caller.
Compare direct calls with a reusable recipe.
01 / CALLERChooses the approach
buildFooterReport()The caller creates a fresh ReportBuilder, chooses title, body and footer, then calls build(). No director is used.
Independent report jobs start with fresh builders.
02 / BUILDERSame class
Keeps the editable draft and implements the construction steps. For this example, the chosen steps are:
withTitle(…)withBody(…)withFooter(…)build(): ReportTitle and body are required. build() checks them before returning a valid product.
03 / PRODUCTSame type
The finished object, separate from the builder. Later draft edits do not change this snapshot.
REPORT / COMPLETED SNAPSHOT
We shipped a new lesson.
04 / DIRECTOR ROLEOptional · not used here
Coordinates title, body, summary, chart, footer and build() on a supplied builder. It knows the recipe; ReportBuilder knows how to assemble and validate the report.
This function plays the director role. A separate director class is not required.
Direct construction: the caller chooses the steps. ReportBuilder validates the draft and returns a Report with a footer.
Try the demo below: assemble a draft, build a report, then edit the draft and compare them.
WATCH IT TAKE SHAPE
Add named parts to an unfinished draft. Build a report when it’s ready, then keep editing the draft to see what stays separate.
1 / CHOOSE NAMED STEPS
Required parts first, or optional ones first. Build checks that the essentials are there.
2 / THE BUILDER
0 of 2 required parts ready
BUILDER / CURRENT DRAFT
Body not set
Optional parts may be left out.
3 / THE PRODUCT
Created only when you call build()
Your finished report will appear here.
Add the required parts, then build.
Start with an empty builder. Add a title and body, then build your report.
Many optional parts, repeated assembly recipes, or several representations built through similar operations can benefit from a dedicated builder.
A constructor, factory function, options object, or Kotlin named arguments may be enough for simple data. Fluent method chaining alone does not make a useful Builder.
Feel the cost of a growing argument list, then assemble a report with named steps.
Live report workshop · optional practiceBACK FOR A REFRESHERRoles, construction code, product guarantees, and when simpler alternatives work.
TypeScript + Kotlin · bookmarkable