Created
November 3, 2019 14:24
-
-
Save chelseatroy/34c49c8495cc48d2cad07fa7fc858636 to your computer and use it in GitHub Desktop.
Visitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WidthVisitor implements BoxVisitor { | |
int visitBob(BobBox box) { | |
return box.getWidth(); | |
} | |
int visitAlice(AliceBox box) { | |
return Math.abs(box.getX2() - box.getX1()); | |
} | |
} | |
class HeightVisitor implements BoxVisitor { | |
int visitBob(BobBox box) { | |
return box.getHeight(); | |
} | |
int visitAlice(AliceBox box) { | |
return Math.abs(box.getY2() - box.getY1()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment