O'Reilly logo

Design Patterns in Java™, Second Edition by William C. Wake, Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required