Now that’s a lot of properties! (@kyle made sure a survival kit has everything we need) which means that every time we need to add a new survival kit to an order we have to create everything that comes with it. Not only that but there is a risk of mistyping the cost, which pottentialy could make the kit more expensive, or cheaper than what it’s actually worth. Not fun.
The great thing about the #build method is that it can encapsulate the complexity of creating a SurvivalKit. The client code doesn’t need to know how to go on creating a TShirt or a Mug. All is interested in is a survival kit and that’s what it gets!
The #build method also provides a place to return objects in the required state while any “setter” method in the builder can be used to perform assertions on the property to set. So in essence a builder helps you create immutable objects since once the object is “built” you can’t change it. (notice how the setters are missing from the SurvivalKit)
As an extra bonus you get to specify constant values for any of your properties. (e.g. the cost!)
Make sure that you document your builder on any default values it might use as well as the state that the object is returned in.
Disclaimer: The builder specified above is great if you have a single “configuration” of survival kits and that’s usually the case. We’ll see why the builder is complimentary to the factory and not a replacement altogether.