Improved comments on visitor pattern example.
This commit is contained in:
parent
b12243b94c
commit
6e49fc01ab
@ -2,10 +2,15 @@ package com.iluwatar;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Visitor pattern defines mechanism to apply operations (UnitVisitor) on nodes
|
* Visitor pattern defines mechanism to apply operations on nodes
|
||||||
* (Unit) in hierarchy. New operations can be added without altering the node
|
* in hierarchy. New operations can be added without altering the node
|
||||||
* interface.
|
* interface.
|
||||||
*
|
*
|
||||||
|
* In this example there is a unit hierarchy beginning from Commander.
|
||||||
|
* This hierarchy is traversed by visitors. SoldierVisitor applies
|
||||||
|
* its operation on Soldiers, SergeantVisitor on Sergeants and so
|
||||||
|
* on.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.iluwatar;
|
package com.iluwatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Commander
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Commander extends Unit {
|
public class Commander extends Unit {
|
||||||
|
|
||||||
public Commander(Unit... children) {
|
public Commander(Unit... children) {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.iluwatar;
|
package com.iluwatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* CommanderVisitor
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class CommanderVisitor implements UnitVisitor {
|
public class CommanderVisitor implements UnitVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.iluwatar;
|
package com.iluwatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Sergeant
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Sergeant extends Unit {
|
public class Sergeant extends Unit {
|
||||||
|
|
||||||
public Sergeant(Unit... children) {
|
public Sergeant(Unit... children) {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.iluwatar;
|
package com.iluwatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* SergeantVisitor
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class SergeantVisitor implements UnitVisitor {
|
public class SergeantVisitor implements UnitVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.iluwatar;
|
package com.iluwatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Soldier
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Soldier extends Unit {
|
public class Soldier extends Unit {
|
||||||
|
|
||||||
public Soldier(Unit... children) {
|
public Soldier(Unit... children) {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package com.iluwatar;
|
package com.iluwatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* SoldierVisitor
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class SoldierVisitor implements UnitVisitor {
|
public class SoldierVisitor implements UnitVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user