Files
java-design-patterns/visitor/src/main/java/com/iluwatar/App.java
T
2014-08-31 11:35:08 +03:00

24 lines
634 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());
}
}