Hi,

After reading up on the HierarchicalVisitor pattern on C2 (http://c2.com/cgi/wiki?HierarchicalVisitorPattern) I realized that this is what I had been looking for with the DescriptorVisitor that is in the Qi4j SPI.

After some thinking I then implemented it as a generic interface like so:
public interface HierarchicalVisitor<NODE, LEAF, ThrowableType extends Throwable>
        extends Visitor<LEAF, ThrowableType>
{
    boolean visitEnter( NODE visited )
            throws ThrowableType;

    boolean visitLeave( NODE visited )
            throws ThrowableType;
}
---
and added it to all model classes instead of DescriptorVisitor. By not using explicit visit methods in the visitor it becomes easier to add more elements that are visited, but which are not necessarily exposed through an SPI interface. The visitor has to do "if(instanceof)" checks instead, and act on what is being visited.

With this in place I then realized that the dependency binding algorithm could be rewritten as a visitor. So I have now done that and have removed a lot of the unnecessary bind() methods that simply traversed the model.

So, for the next release the ApplicationSPI.visitDescriptor() method is gone, and instead there's an accept(HierarchicalVisitor) method in ApplicationModelSPI instead. All usages of DescriptorVisitor have been replaced with the above.

/Rickard

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

Reply via email to