this post was submitted on 18 Jul 2023
2 points (100.0% liked)

PHP

33 readers
3 users here now

founded 2 years ago
 

Hi! In the realm of software development, creating complex objects often feels like trying to solve a...

you are viewing a single comment's thread
view the rest of the comments
[–] abhibeckert 1 points 2 years ago* (last edited 2 years ago)

The main advantage of a builder is you can create an object in multiple steps instead of one step.

During the builder process the object might temporarily be in an invalid state - for example perhaps you can't easily access the product price. You wouldn't want price to be an optional value for the actual product class, but it can be optional for the builder (as long as it's set once build() is called).