责任链模式(Chain of Responsibility Pattern)


责任链模式(Chain of Responsibility Pattern)




介绍
为解除请求的发送者和接收者之间耦合,而使多个对象都有机会处理这个请求。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。


示例
有一个Message实体类,某个类对它的操作有Insert()方法。现在要求根据插入信息的字符长度,让不同的对象去处理,这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。1.jpg.png


MessageModel

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.ChainOfResponsibility
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// Message实体类
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class MessageModel
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 构造函数
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="msg">Message内容</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <param name="pt">Message发布时间</param>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public MessageModel(string msg, DateTime pt)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
this._message = msg;
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
this._publishTime = pt;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
private string _message;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// Message内容
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public string Message
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
get { return _message; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
set { _message = value; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
private DateTime _publishTime;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// Message发布时间
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public DateTime PublishTime
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
get { return _publishTime; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            
set { _publishTime = value; }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


SqlMessage

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.ChainOfResponsibility
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// Sql方式操作Message
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class SqlMessage
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns></returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public bool Insert(MessageModel mm)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 代码略
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            return true;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


AbstractExecutor

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.ChainOfResponsibility
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// 抽象处理者(Handler)角色
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public abstract class AbstractExecutor
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 抽象处理者(Handler)角色
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
protected AbstractExecutor _executor;
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 设置责任链的上一级对象
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <param name="executor"></param>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public void SetSuccessor(AbstractExecutor executor)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
this._executor = executor;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns>执行者;内容;时间</returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public abstract string Insert(MessageModel mm);
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


Employee

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.ChainOfResponsibility
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// 具体处理者(ConcreteHandler)角色
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class Employee : AbstractExecutor
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns>执行者;内容;时间</returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override string Insert(MessageModel mm)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
string rtn = "";
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 插入的信息字符数小于5
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            if (mm.Message.Length < 5)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                SqlMessage m = 
new SqlMessage();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                
if (m.Insert(mm))
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif                {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                    rtn = "
执行者:雇员" + " 内容:" + mm.Message + " 时间:" + mm.PublishTime.ToString();
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif                }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 否则让上级去执行
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            else if (base._executor != null)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                rtn = _executor.Insert(mm);
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
return rtn;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


Leader

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.ChainOfResponsibility
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// 抽象处理者(Handler)角色
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class Leader : AbstractExecutor
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns>执行者;内容;时间</returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override string Insert(MessageModel mm)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
string rtn = "";
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 插入的信息字符数小于10
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            if (mm.Message.Length < 10)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                SqlMessage m = 
new SqlMessage();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                
if (m.Insert(mm))
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif                {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                    rtn = "
执行者:主管" + " 内容:" + mm.Message + " 时间:" + mm.PublishTime.ToString();
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif                }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 否则让上级去执行
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            else if (base._executor != null)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                rtn = _executor.Insert(mm);
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
return rtn;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


Manager

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections.Generic;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Text;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
namespace Pattern.ChainOfResponsibility
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
/// 抽象处理者(Handler)角色
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
public class Manager : AbstractExecutor
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        
/// <summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// 插入Message
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// </summary>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
/// <param name="mm">Message实体对象</param>
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        
/// <returns>执行者;内容;时间</returns>
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        
public override string Insert(MessageModel mm)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif        {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
string rtn = "";
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
// 插入的信息字符数小于15
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
            if (mm.Message.Length < 15)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                SqlMessage m = 
new SqlMessage();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                
if (m.Insert(mm))
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif                {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                    rtn = "
执行者:经理" + " 内容:" + mm.Message + " 时间:" + mm.PublishTime.ToString();
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif                }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
else
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif            {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif                rtn = "
你所插入的Message不符合要求";
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif            
return rtn;
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif



client

http://www.cnblogs.com/Images/OutliningIndicators/None.gifusing System;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Data;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Configuration;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Collections;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.Security;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI.WebControls;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI.WebControls.WebParts;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using System.Web.UI.HtmlControls;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
using Pattern.ChainOfResponsibility;
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
public partial class ChainOfResponsibility : System.Web.UI.Page
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif{
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif    {
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        AbstractExecutor employee = 
new Employee();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        AbstractExecutor leader = 
new Leader();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        AbstractExecutor manager = 
new Manager();
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        employee.SetSuccessor(leader);
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        leader.SetSuccessor(manager);
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(employee.Insert(
new MessageModel("abcd", DateTime.Now)));
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write("<br />");
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(employee.Insert(
new MessageModel("abcdefgh", DateTime.Now)));
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write("<br />");
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(employee.Insert(
new MessageModel("abcdefghigkl", DateTime.Now)));
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write("<br />");
http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif        Response.Write(employee.Insert(
new MessageModel("abcdefghigklmnop", DateTime.Now)));
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.cnblogs.com/Images/OutliningIndicators/None.gif


运行结果
执行者:雇员 内容:abcd 时间:2007-4-22 20:04:41
执行者:主管 内容:abcdefgh 时间:2007-4-22 20:04:41
执行者:经理 内容:abcdefghigkl 时间:2007-4-22 20:04:41
你所插入的Message不符合要求


果糖网