[索引页]
[源码下载]


乐在其中设计模式(C#) - 命令模式(Command Pattern)


作者:webabcd


介绍
将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可取消的操作。


示例
有一个Message实体类,某个类对它的操作有Insert()和Delete()方法。现在要求可以对之前的所有操作做撤销和重复。
乐在其中设计模式(C#) - 命令模式(Command Pattern)


MessageModel
乐在其中设计模式(C#) - 命令模式(Command Pattern)using System;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Text;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
namespace Pattern.Command
}

Action
乐在其中设计模式(C#) - 命令模式(Command Pattern)using System;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Text;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
namespace Pattern.Command

SqlMessage
乐在其中设计模式(C#) - 命令模式(Command Pattern)using System;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Text;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
namespace Pattern.Command

ICommand
乐在其中设计模式(C#) - 命令模式(Command Pattern)using System;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Text;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
namespace Pattern.Command

SqlMessageCommand
乐在其中设计模式(C#) - 命令模式(Command Pattern)using System;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Text;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
namespace Pattern.Command

Message
乐在其中设计模式(C#) - 命令模式(Command Pattern)using System;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Text;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
namespace Pattern.Command


client
乐在其中设计模式(C#) - 命令模式(Command Pattern)using System;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Data;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Configuration;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Collections;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Web;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Web.Security;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Web.UI;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Web.UI.WebControls;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Web.UI.WebControls.WebParts;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using System.Web.UI.HtmlControls;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
using Pattern.Command;
乐在其中设计模式(C#) - 命令模式(Command Pattern)
乐在其中设计模式(C#) - 命令模式(Command Pattern)
public partial class Command : System.Web.UI.Page

运行结果
操作
Insert:第1条
Insert:第2条
Insert:第3条
Insert:第4条
Delete:第2条
Insert:第5条
Delete:第3条
Insert:第6条
Insert:第7条

撤销4次操作
Delete:第7条 Delete:第6条 Insert:第3条 Delete:第5条

重复2次操作
Insert:第5条 Delete:第3条

撤销3次操作
Insert:第3条 Delete:第5条 Insert:第2条


参考
http://www.dofactory.com/Patterns/PatternCommand.aspx


OK
[源码下载]

相关文章:

  • 2021-12-17
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-01-21
  • 2021-06-12
  • 2021-05-30
猜你喜欢
  • 2021-07-18
  • 2021-09-18
  • 2021-06-28
  • 2021-08-04
相关资源
相似解决方案