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
using System.Collections.Generic; | |
public class House | |
{ | |
public List<Room> Rooms; | |
public void AcceptVisitor(IVisitor visitor) | |
{ | |
//The handyman will perform checks on this house | |
//(e.g. check the outside walls) |
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 abstract class Unit | |
{ | |
public string Name; | |
public State State; | |
public abstract void AcceptVisitor(IVisitor visitor); | |
} | |
public class ProcessUnit : Unit | |
{ |
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 interface IVisitor | |
{ | |
void VisitProcessUnit(ProcessUnit unit); | |
void VisitAgentUnit(AgentUnit unit); | |
} |
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 class StartUnitVisitor : IVisitor | |
{ | |
public void VisitProcessUnit(ProcessUnit unit) | |
{ | |
foreach (var childUnit in unit.ChildUnits) | |
childUnit.AcceptVisitor(this); | |
} | |
public void VisitAgentUnit(AgentUnit unit) | |
{ |
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
var visitor = new StartUnitVisitor(); | |
processUnitToStart.AcceptVisitor(visitor); | |
Console.WriteLine("Process unit {0} started", processUnitToStart); |