O'Reilly logo

Domain Specific Languages by Martin Fowler

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

Chapter 14. Construction Builder

Incrementally create an immutable object with a builder that stores constructor arguments in fields.

image

14.1 How It Works

The basic recipe for a Construction Builder is very simple. You need to create an immutable object, which I’ll call the product, in a gradual manner. So, take each of the constructor arguments of the product and make a field for each one. Add further fields for any other attributes of the product that you’re collecting. Finally, add a method to create and return a new product object assembled from all the data in the Construction Builder.

You may want to add some lifecycle controls to the Construction ...

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