Wednesday, March 31, 2010

New Construction Home Builder

How it Works

The basic recipie for 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 life-cycle controls to the Construction Builder. Such controls might check to see if you have enough information yet to create the product.

You might set a flag once you've returned a product to stop you returning it again, or put the created product in a field. You might raise an error if you try to add new attributes to the Construction Builder once you've created the product.

Construction Builders can be grouped into deeper structures that combine multiple Construction Builders. They can then produce a group of related objects rather than a single object.

When to use it

Construction Builder is useful whenever you need to create an object with multiple immutable fields, but you gather the values for these fields gradually. A Construction Builder gives you a coherent place to put all this data before you actually create the product.

The simplest alternative to Construction Builder is to capture the information in local variables, or loose fields. This works fine for one or two products, but soon gets confusing if you need to create a bunch of objects at once, such as when you're parsing.

Another alternative is to create actual framework objects but when you gather data for an immutable attribute to create a new copy of the framework object with that one attribute changed and replace the old one.

This saves you having to write a Construction Builder, but is generally more awkward to do and follow. In particular it doesn't work if you have multiple references to the object, or at least it makes it more difficult as you have to replace every reference.

Using Construction Builder is usually the best way to handle this problem, but remember you only need it when you have immutable fields. If that's not the case, then just create your product objects directly.
Read Full Article, Click Here Now .... Add to Technorati Favorites Bookmark and Share

Architectural designs of houses , Architecture designs , Property listings , Property management , Bridge construction 2012

Back to TOP