Initializer Build idiom – facts and fallacies

Nowadays, most Java developers are quite familiar with the so called Initializer Build idiom. It’s meanwhile a well known idiom for building hierarchical structures, especially when creating formations which follow the composite pattern.

In short, you mostly want to avoid building those structures in a verbose way by instantiating each element separately and assembling the elements afterwards (that is defining the parent – child relationships), but combine both (instantiation and assembling) within one step in a more concise way.

I applied the idiom the other day, only to detect some fallacies (i was falling for) that will come with that idiom, if you don’t attend to the given specialities. The following sections will give a brief overview of the specific facts that will come with that idiom along with some of the more severe fallacies you have to be aware of. Read the rest of this entry »

Posted in java. 4 Comments »