Solution: Create a Fluent Pizza Order Builder
Implement a fluent builder that supports optional fields and enforces a required size before finalizing the pizza order.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 2–6: We initialize the builder’s internal state—
sizestarts empty,toppingsas an array, andnoteundefined—to capture user inputs cleanly.Lines 8–21: We define fluent setter methods (
withSize,addTopping,withNote) that update the respective fields and returnthis, allowing flexible chaining in any order.Lines 24–26: In
.build()...