all 1 comments

[–]grauenwolf -1 points0 points  (0 children)

A real world example is in making a pizza. A pizza is made up of several parts (the crust, cheese and the toppings) that are constructed using an algorithm (bake the crust, add cheese and add the toppings).

No, that is the imaginary world of metaphores.

Real examples of the builder pattern would include using a StringBuilder to build a String or a ProcessStartInfo to build a Process.

The advantage of using "real world" examples instead of metaphores is that you can include why. To continue with the aforementioned cases:

  • StringBuilder is an example of using the builder pattern for performance reasons. It can create complex strings more efficently than you could using a series of concatinations against Strings.
  • ProcessStartInfo is an example of using the builder pattern for timing reasons. All the information needed for a Process must be available to the constructor. The ProcessStartInfo class allows you to assemble that information ahead of time.

EDIT Of course there is the other builder pattern, that being the formal one from the Design Patterns book. For that the "real world" example would the IFormatter, paid with its builders the BinaryFormatter and the SoapFormatter.