net.sf.jga.fn

Interface Visitor

public interface Visitor

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);
    }

    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 David A. Hall

Author: David A. Hall

Method Summary
voidvisit(Visitable visitable)
Call-back method, called by the Visitable object in response to a call to its accept(Visitor) method.

Method Detail

visit

public void visit(Visitable visitable)
Call-back method, called by the Visitable object in response to a call to its accept(Visitor) method.