CMSC 132A Lecture 23: Visitor Pattern Rehash
CMSC132A Lecture 23: Visitor Pattern Rehash
Boolean testShapeAreaVisitor(tester.Tester t){
ShapeVisitor<Double> area = new ShapeAreaVisitor();
Return t.checkExpect(s1.accept(area),32.0);
}
Public Double visitCircle(Circ c){
Return c.r*c.r*Math.PI;
}
Look at the visitCombo method
Return c.s1.accept(this)+c.s2.accept(this);
Return c.s1.accept(area)+c.s2.accept(area);
Something else
Which of these is the correct return statement?
It is Return c.s1.accept(this)+c.s2.accept(this);
Return c.s1.accept(area)+c.s2.accept(area); is not defined. What we mean by the this
keyword is area, but area is not defined.
One is correct because we use a recursive call on the method.
What if you want to deal with people’s bank accounts?
Class Bank{
Integer int;
Bank(Integer int){
this.int=int;