Explore Topics
Builder is a **creational** GoF pattern that separates **how** a complex object is constructed from **what** the object ultimately is. A single Director runs the same construction sequence; different Concrete Builders plug into that sequence and produce different Products. Build a House: the Director always calls `foundation β walls β roof β windows β garage`, but the StoneHouseBuilder produces a slate-roofed brick home with a garage, while the WoodHouseBuilder produces a cedar cabin on stilts with no garage at all.
- **Construction** (the step sequence) is separated from **representation** (the final Product). The Director owns the sequence, the Builder owns the steps, the Product is the result.
- The **same** Director recipe drives **different** Concrete Builders to produce **different** Products β that is the pattern's defining mechanic.
- The Product never exists in a half-built state visible to the Client β the Builder returns it only after the last step (`getRoaster()` / `build()`).
- A Concrete Builder can **skip** a step (return immediately) β the same Director recipe can produce a Product that lacks one of the parts, without changing the Director.
- β¦One Director, N Concrete Builders, N different Products β adding a new Product variant means a new ConcreteBuilder, no change to Director or Client.
- β¦The complex construction logic is encapsulated in one place (the Concrete Builder) β Client code stays a 3-line script: pick a Builder, hand it to the Director, collect the Product.
- β¦Final Product can be **immutable** β all fields can be `final`, set exactly once when the Builder hands them off.
- β³Three new classes for every Product family (Builder interface + N ConcreteBuilders + Director) before you write a single line of business logic.
- β³For simple objects (a Point with two coordinates), a constructor is shorter, clearer, and faster.
- β³The Director and the Builder both know the Product's shape β if the Product grows a new component, BOTH must change in lockstep.