Hey,

In continuation of the previous post, here's a suggestion for how to 
mutate ValueComposites.

We introduce ValueBuilderFactory/ValueBuilder for creation of 
ValueComposites. VBF is basically a copy of CBF. ValueBuilder is:
public interface ValueBuilder<T extends ValueComposite>
     extends Iterable<T>
{
     /**
      * Set state of value builder to that of the given value instance.
      *
      * @param value whose state should be copied to this builder
      * @return the builder itself
      */
     ValueBuilder<T> copyOf(T value);

     /**
      * Get a representation of the state for the new Value.
      * It is possible to access and update properties and associations,
      * even immutable ones since the builder represents the initial state.
      *
      * @return a mutable instance of the Value type
      */
     T value();

     /**
      * Create a new Composite instance.
      *
      * @return a new Composite instance
      * @throws org.qi4j.api.common.ConstructionException thrown if it 
was not possible to instantiate the Composite
      */
     T newInstance()
         throws ConstructionException;
}
--
The idea here is that you start either from scratch and just set initial 
values and do newInstance(), or you start with an existing value, which 
you then copy into this builder by doing copyOf(oldValue). Then the 
builder instantiates a *mutable* copy on value(), which the user can 
mutate and do Swing binding on, and so on, and the final instance is 
created by doing newInstance() which creates an immutable instance with 
the configured state.

This should make it trivial to both view and edit values, and then write 
back the new state to the entity.

What do you think? Does this make sense?

/Rickard

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

Reply via email to