Skip to content

Instantly share code, notes, and snippets.

@adibfara
Created October 18, 2023 09:17
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 adibfara/18dc974bd3752365560470a25ce38cb4 to your computer and use it in GitHub Desktop.
Save adibfara/18dc974bd3752365560470a25ce38cb4 to your computer and use it in GitHub Desktop.
Visitor Pattern Usage
public static void main(String[] args) {
var ensemble = new Container(
new Item[]{
new Box(2),
new Container(new Item[]{
new Box(3),
new Box(4)}
)});
ensemble.visit(new PrinterVisitor());
System.out.println();
System.out.println("Total weight is: " + ensemble.visit(new WeightVisitor()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment