Created
October 18, 2023 09:17
-
-
Save adibfara/18dc974bd3752365560470a25ce38cb4 to your computer and use it in GitHub Desktop.
Visitor Pattern Usage
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
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