Ben Northrop

Decisions and software development

Design Pattern's Group Questions > Builder

November 11th, 2006


Separate the construction of a complex object from its representation so that the same construction process can create different representations. -Design Patterns, GoF


1) What is the role of the Director? Why is it separate from the Builder?

2) Do the build methods in the builder return anything?

3) Why do there need to be multiple build methods in a Builder?

4) What are the forces that would compel you to use a Builder?

5) Before the Builder returns the final object, does it validate that it was built sufficiently?



Examples Which are Builders?

1) Email message builder Patterns in Java, Mark Grand


Implement It!

You are the lead programmer at a collection agency. Your task is to create a delinquency notice (object), which could be sent out up to 3 times to a person (depending on how delinquent they are!). The first notice should be nice, the second firm but cordial, and the final downright nasty. The notice has 3 parts:

   the greeting, which takes a first and last name

   the message body, which takes the amount owed and the days delinquent

   the closing line, which takes nothing.

Implement this using the Builder pattern. Is the Builder appropriate here?




   Builder Pattern (Wikipedia)

I believe that software development is fundamentally about making decisions, and so this is what I write about (mostly). I've been building software for about 20 years now, as a developer, tech lead, and architect. I have two degrees from Carnegie Mellon University, most recently one in philosophy (thesis here). I live in Pittsburgh, PA with my wife, 3 energetic boys, and dog. Subscribe here or write me at ben dot northrop at gmail dot com.

Got a Comment?

Sign up to hear about the next post!

If you liked this article and want to hear about the next one, enter your email below. I don't spam - you'll only receive an email when there's a new post (which is about once a month, tops). It's all low-key, straight from me.

Comments ()

 None so far!