mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 12:58:37 +00:00
23 lines
649 B
Java
23 lines
649 B
Java
package com.iluwatar;
|
|
|
|
/**
|
|
*
|
|
* Visitor pattern defines mechanism to apply operations (UnitVisitor) on nodes
|
|
* (Unit) in hierarchy. New operations can be added without altering the node
|
|
* interface.
|
|
*
|
|
*/
|
|
public class App {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Commander commander = new Commander(
|
|
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
|
|
new Sergeant(new Soldier(), new Soldier(), new Soldier()));
|
|
commander.accept(new SoldierVisitor());
|
|
commander.accept(new SergeantVisitor());
|
|
commander.accept(new CommanderVisitor());
|
|
|
|
}
|
|
}
|