Leader
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.ChainOfResponsibility
{
/**//// <summary>
/// 抽象處理者(Handler)角色
/// </summary>
public class Leader : AbstractExecutor
{
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns>執行者;內容;時間</returns>
public override string Insert(MessageModel mm)
{
string rtn = "";
// 插入的信息字符數小於10
if (mm.Message.Length < 10)
{
SqlMessage m = new SqlMessage();
if (m.Insert(mm))
{
rtn = "執行者:主管" + " 內容:" + mm.Message + " 時間:" + mm.PublishTime.ToString();
}
}
// 否則讓上級去執行
else if (base._executor != null)
{
rtn = _executor.Insert(mm);
}
return rtn;
}
}
}
Manager
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.ChainOfResponsibility
{
/**//// <summary>
/// 抽象處理者(Handler)角色
/// </summary>
public class Manager : AbstractExecutor
{
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns>執行者;內容;時間</returns>
public override string Insert(MessageModel mm)
{
string rtn = "";
// 插入的信息字符數小於15
if (mm.Message.Length < 15)
{
SqlMessage m = new SqlMessage();
if (m.Insert(mm))
{
rtn = "執行者:經理" + " 內容:" + mm.Message + " 時間:" + mm.PublishTime.ToString();
}
}
else
{
rtn = "你所插入的Message不符合要求";
}
return rtn;
}
}
}