I just had this crazy idea;

public interface MyValueBuilder
{
    @Construction
    MyValue create( String name, LocalDate expiry );

    @Construction
    MyValue create( String name, String description, LocalDate expiry );
}

public interface MyValue
{
    interface State
    {
        Property<String> name();

        @Optional
        Property<String> description();

        Property<LocalDate> expiry();
    }
}

Now, the MyValueBuilder could simply be a service, which has a generic
mixin that uses the "parameter names" to initialize the properties
accordingly.

But it would be much neater if the MyValueBuilder is registered at assembly
as the ValueBuilder for the MyValue type, and that it is automatically
returned. Of course, in that case it is a subinterface of
ValueBuilder<MyValue>


MyValueBuilder builder = vbf.newValueBuilder(MyValueBuilder.class);
MyValue first = builder.create( "NIclas", LocalDate.now().plusDays(1) );
MyValue second = builder.create( "Paul", "More stamina",
LocalDate.now().plusDays(14) );


BUT WAIT, there is more... But then this could mean that the MyValueBuilder
would end up being a Composite with a Mixin, i.e. the Composite Builders
could themselves be Composites???  Chicken-Egg problem?

Any thoughts?


Cheers
-- 
Niclas Hedhman, Software Developer
http://polygene.apache.org - New Energy for Java

Reply via email to