Defines an interface for classes that may interpret functors or predicates.
jga uses the AcyclicVisitor
pattern to provide a structure for implementing Visitor. Within jga, each
class that implements Visitable does so with the following boilerplate:
public class Foo implements Visitable
public void accept(net.sf.jga.fn.Visitor v) {
if (v instanceof Foo.Visitor)
((Foo.Visitor)v).visit(this);
else
v.visit(this);
}
public interface Visitor extends net.sf.jga.fn.Visitor {
public void visit(Foo host);
}
Implementations of Visitor will declare suport for a given class by
implementing that class' Visitor interface.
public class FooBarCounter implements Foo.Visitor, Bar.Visitor {
private int count = 0;
public int getCount() { return count; }
public void visit(Visitable host) {}
public void visit(Foo host) { ++count; }
public void visit(Bar host) { ++count; }
}
Copyright © 2002-2005 David A. Hall
author: David A. Hall |