15 Builder

YOU DONT ALWAYS have all the information needed for an object when it’s time to construct it. It is especially convenient to allow step-by-step construction of a target object when you acquire the parameters for a constructor gradually, as happens with parsers and may happen with a user interface. Or, you might simply want to reduce the size of a class whose construction is relatively complicated but has little to do with the main focus of the class.

The intent of the BUILDER pattern is to move the construction logic for an object outside the class to be instantiated.

An Ordinary Builder

A common situation in which you can benefit from BUILDER occurs when data that defines a desired object is embedded in a text string. ...

Get Design Patterns in Java™, Second Edition 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.