On 2009-12-30 08.26, Alex Shneyderman wrote:
Something like this:TransientBuilder<QrmTableMapping> bldr = ...; return bldr.newInstance( new Intializer<QrmTableMapping> { void initialize(QrmTableMapping qtm) { // init code here } } ); Initializer is an interface that looks something like: interface Initializer<T> { void init( T instance ); }
One problem here is that it assumes that the code that creates the builder can immediately know the values. For server-code that is fine, but for clients I have a lot of cases where I create builders, then bind the prototype instance to a GUI, and when the user is done, I call newInstance to get a "snapshot" of the UI to use. The creation of the builder and the newInstance call is hence "far apart", so to speak.
With the above you also get an extra anonymous class for every usage, which is kind of "heavy".
I would prefer not to build this into the API, but yeah, if you absolutely want it as a helper that would be fine. Niclas' point about private mixins are also important to consider.
For transients, compared to values, you also have the option of simply creating the instance and then change it before moving on in the code. Only if you really need to initialize it to make it valid do you need builders.
/Rickard _______________________________________________ qi4j-dev mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/qi4j-dev

