Hey all,

I'm curious how you guys think one should go about constructing value 
objects with Qi4j.  I'd sort of like to make as much of my model value 
objects as possible, so things like Address and Money would should be 
value objects.  Typically I see Money as a value object, but Address is 
usually not.  Even in the Money case, you still need at least 4 lines of 
code

        EntityBuilder<MoneyEntityComposite> money = 
unitOfWork.newEntityBuilder( MoneyEntityComposite.class );
        money.stateOfComposite().amount().set( amount );
        money.stateOfComposite().currency().set( Currency.getInstance( 
currencyCode ) );

        return money.newInstance();


The natural conclusion is to use factories to wrap that, register the 
factories as Services and have them injected wherever I need them.  This 
is likely going to result in a bunch of factories as there would be one 
for each composite type.

So, I guess the question is, would it make more sense to have a single 
super factory that knows how to create each of those or would a bunch of 
smaller factories work just as well? 

I guess one of the beauties of Qi4j is that I can easily choose and then 
move to the other later if it seems better.  I suppose I can even do 
both where I have all the small factories interfaces with mixins and 
then combine them all into one super factory and have them injected as 
the more narrowly scoped factory when I just need a particular type and 
have it as the broader super factory when I need to create a bunch of 
different value objects.  I think I've convinced myself that that's the 
way to go.  What do you think?

Rich

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to