Chapter 15. Builder

The BUILDER pattern moves the construction logic for an object outside the class to instantiate. There are several reasons why you might make this move. You might simply want to reduce the size of a class that has many methods. You might also want to allow step-by-step construction of a target object. This occurs when you acquire the parameters for a constructor gradually, as happens with parsers and may happen with a user interface.

An Ordinary Builder

A common situation where you can benefit from BUILDER occurs when data that defines a desired object is embedded in a text string. As your code looks through (that is, parses) the data, you need to store the data as you find it. Whether your parser is XML-based or hand-crafted, ...

Get Design Patterns in C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.