Tiger下的Visitor

03-05-17 英雄传说
    

public interface Visitable

{

void accept(Visitor<Visitable> visitor);

}

public interface Visitor<A>

{

void visit(A visitable);

}

public class VisitableA implements Visitable

{

public String Call(){

return "AAA";

}

public void accept(Visitor<Visitable> visitor) {

visitor.visit(this);

}

}

public class VisitorA<A> implements Visitor<B>

{ public void visit(A visitable) {

System.out.println(visitable.Call());

}

}

public class Client{

public static void main(String args[])

{

Visitor<Visitable> visitor=new VisitorA<VisitableA>();

Visitable visitable=new VisitableA();

visitable.accept(visitor);

}

}

    

英雄传说
2003-05-17 18:08

jdon不能用尖括号,

改在如下地址:

http://umlchina.smiling.com/group/photo/photoshow.ecgi?photo_id=791122&group_id=9986