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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.