When you have to work with complex nested object structures and you want an easy way to create them and test them, I think it's definitely worthwhile to create a builder. A builder is a fluent DSL to create (domain) objects. Below you can see how that works out
A builder pattern doesn't have to implement a fluent interface, but they do go very nice together.
ReplyDeleteIt might be interesting to note that there are tools to automatically generate your fluent builders, such as this nice eclipse plugin, so you don't have to write out a whole bunch of samey code.