CMSC 132A Lecture 23: Visitor Pattern Rehash

75 views3 pages
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;
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents