|
1 | | -package com.iluwatar.visitor; |
2 | | - |
3 | | -/** |
4 | | - * |
5 | | - * Visitor pattern defines mechanism to apply operations on nodes |
6 | | - * in hierarchy. New operations can be added without altering the node |
7 | | - * interface. |
8 | | - * |
9 | | - * In this example there is a unit hierarchy beginning from Commander. |
10 | | - * This hierarchy is traversed by visitors. SoldierVisitor applies |
11 | | - * its operation on Soldiers, SergeantVisitor on Sergeants and so |
12 | | - * on. |
13 | | - * |
14 | | - */ |
15 | | -public class App { |
16 | | - |
17 | | - public static void main(String[] args) { |
18 | | - |
19 | | - Commander commander = new Commander(new Sergeant(new Soldier(), |
20 | | - new Soldier(), new Soldier()), new Sergeant(new Soldier(), |
21 | | - new Soldier(), new Soldier())); |
22 | | - commander.accept(new SoldierVisitor()); |
23 | | - commander.accept(new SergeantVisitor()); |
24 | | - commander.accept(new CommanderVisitor()); |
25 | | - |
26 | | - } |
27 | | -} |
| 1 | +package com.iluwatar.visitor; |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * Visitor pattern defines mechanism to apply operations on nodes |
| 6 | + * in hierarchy. New operations can be added without altering the node |
| 7 | + * interface. |
| 8 | + * <p> |
| 9 | + * In this example there is a unit hierarchy beginning from {@link Commander}. |
| 10 | + * This hierarchy is traversed by visitors. {@link SoldierVisitor} applies |
| 11 | + * its operation on {@link Soldier}s, {@link SergeantVisitor} on {@link Sergeant}s and so |
| 12 | + * on. |
| 13 | + * |
| 14 | + */ |
| 15 | +public class App { |
| 16 | + |
| 17 | + /** |
| 18 | + * Program entry point |
| 19 | + * @param args command line args |
| 20 | + */ |
| 21 | + public static void main(String[] args) { |
| 22 | + |
| 23 | + Commander commander = new Commander(new Sergeant(new Soldier(), |
| 24 | + new Soldier(), new Soldier()), new Sergeant(new Soldier(), |
| 25 | + new Soldier(), new Soldier())); |
| 26 | + commander.accept(new SoldierVisitor()); |
| 27 | + commander.accept(new SergeantVisitor()); |
| 28 | + commander.accept(new CommanderVisitor()); |
| 29 | + |
| 30 | + } |
| 31 | +} |
0 commit comments