Skip to content

Instantly share code, notes, and snippets.

View StartUnitVisitorExample.cs
var visitor = new StartUnitVisitor();
processUnitToStart.AcceptVisitor(visitor);
Console.WriteLine("Process unit {0} started", processUnitToStart);
View StartUnitVisitor.cs
public class StartUnitVisitor : IVisitor
{
public void VisitProcessUnit(ProcessUnit unit)
{
foreach (var childUnit in unit.ChildUnits)
childUnit.AcceptVisitor(this);
}
public void VisitAgentUnit(AgentUnit unit)
{
View IVisitor.cs
public interface IVisitor
{
void VisitProcessUnit(ProcessUnit unit);
void VisitAgentUnit(AgentUnit unit);
}
@kosanmil
kosanmil / Unit.cs
Last active Feb 2, 2019
Snippet containing implementation of Unit, ProcessUnit and AgentUnit
View Unit.cs
public abstract class Unit
{
public string Name;
public State State;
public abstract void AcceptVisitor(IVisitor visitor);
}
public class ProcessUnit : Unit
{
View HandymanVisitorExample.cs
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)
You can’t perform that action at this time.