Yes, interesting question this one, since you on one hand want to keep
code free of Qi4j specific stuff as well, right.

So, let's say we have

public interface Def
{
    Property<String> habba();
    Property<Integer> zout();
}

public interface Abc
{}

where Abc needs to create Def instances for some reason. Both are
composite in nature, but we want to avoid @Structure injection in
either one.

so in the Abc mixins could do;

public class AbcMixin
    implements Abc
{
    private DefFactory factory;

    public AbcMixin( @Service DefFactory factory )
    {
        this.factory = factory;
    }
:
:
    Def def = factory.create( args );
:
:
}

That is fairly straight forward.

Can this be made more generic??

Well, the minimalistic view would be;

public interface InstanceFactory<T>
{
    T create( Object... args );
}

But that makes the argument-to-prototype state setting impossible...

How about?

public interface InstanceFactory<T>
{
}

public interface DefFactory extends InstanceFactory<Def>
{
    Def create( String habba, Integer zout );
}

but AFAIU, it is not possible to extract the names of the arguments
and type alone is not good enough, so no matching can be inferred by a
generic implementation.

Then we end up with

public interface DefFactory extends InstanceFactory<Def>
{
    Def create( Def template );
}

where the Def provided is "cloned" from a POJO or a Composite.

But then you still end with a lot of lines of code to set up the Pojo.

So, all in all, I think that custom made factories seems to be the
simplest way forward. But I wanted to elaborate on my thinking, and
asking if anyone else see some other way that is better....


Cheers
Niclas

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

Reply via email to