Ben Northrop


Decisions and software development


Design Pattern's Group Questions > Builder


November 11th, 2006


Intent

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

Questions

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?

 

 

References

   Builder Pattern (Wikipedia)

I believe that software development is fundamentally about making decisions, and so this is what I write about (mostly). I'm a Distinguished Technical Consultant for Summa and 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 at summa-tech 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!