AbstractVisitor
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Visitor
{
/**//// <summary>
/// 抽象訪問者(Visitor)
/// </summary>
public abstract class AbstractVisitor
{
/**//// <summary>
/// 執行抽象元素的方法
/// </summary>
/// <param name="abstractElement">抽象元素</param>
/// <returns></returns>
public abstract string Visit(AbstractElement abstractElement);
}
}
InsertVisitor
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Visitor
{
/**//// <summary>
/// Insert訪問者(ConcreteVisitor)
/// </summary>
public class InsertVisitor : AbstractVisitor
{
/**//// <summary>
/// 執行Message的Insert()方法
/// </summary>
/// <param name="abstractElement">抽象元素</param>
/// <returns></returns>
public override string Visit(AbstractElement abstractElement)
{
Message m = abstractElement as Message;
return m.Insert().ToString() + "<br />";
}
}
}
GetVisitor
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Visitor
{
/**//// <summary>
/// Get訪問者(ConcreteVisitor)
/// </summary>
public class GetVisitor : AbstractVisitor
{
/**//// <summary>
/// 執行Message的Get()方法
/// </summary>
/// <param name="abstractElement">抽象元素</param>
/// <returns></returns>
public override string Visit(AbstractElement abstractElement)
{
Message m = abstractElement as Message;
return m.Get()[0].Message + " " + m.Get()[0].PublishTime.ToString() + "<br />";
}
}
}