Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 3, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/34c49c8495cc48d2cad07fa7fc858636 to your computer and use it in GitHub Desktop.
Save chelseatroy/34c49c8495cc48d2cad07fa7fc858636 to your computer and use it in GitHub Desktop.
Visitor
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