Exercise: Builder
This exercise puts the Builder pattern into code. You will implement a pizza builder that accumulates configuration through setter-style methods and produces the finished object only when build is called.
Scenario
A pizza configuration session receives a sequence of commands. Only the build command
produces output; the others configure the builder silently and return the builder itself
so calls can be chained.
Commands
The program reads a list of commands, one per line, and prints one line of output for each build command.
| Command | Behavior | Output |
|---|---|---|
["new"] | Reset the builder to a clean slate for the next pizza | (none) |
["size", s] | Set the pizza size to small, medium, or large | (none) |
["top", name] | Add a topping; multiple toppings accumulate in order | (none) |
["build"] | Assemble and describe the pizza | "Pizza: <size>, toppings: <comma-joined toppings>", or "Pizza: <size>, toppings: none" if no toppings were added |
If no size command was issued before build, the default size is medium.
7 size large top pepperoni top mushrooms build new top olives build
Pizza: large, toppings: pepperoni, mushrooms Pizza: medium, toppings: olives
Your task
Fill in set_size, add_topping, and build on PizzaBuilder, and __str__ on Pizza, so the build command produces the output above.