当前位置: 首页 > news >正文

网站婚庆模板免费咨询婚姻律师回答在线

网站婚庆模板,免费咨询婚姻律师回答在线,wordpress 挖矿脚本,需要推广的软件前言 命令模式的关键通过将请求封装成一个对象#xff0c;使命令的发送者和接收者解耦。这种方式能更方便地添加新的命令#xff0c;如执行命令的排队、延迟、撤销和重做等操作。 代码 #region 基础的命令模式 //命令#xff08;抽象类#xff09; public abstract class …前言 命令模式的关键通过将请求封装成一个对象使命令的发送者和接收者解耦。这种方式能更方便地添加新的命令如执行命令的排队、延迟、撤销和重做等操作。 代码 #region 基础的命令模式 //命令抽象类 public abstract class Command {public abstract void Execute(); } //发送命令 public class SendCommand : Command {private Receiver receiver;public SendCommand(Receiver receiver){this.receiver receiver;}public override void Execute(){receiver.Execute();} } //接收命令 public class Receiver {public void Execute(){Console.WriteLine(receiver execute the command...);} } //调用者命令 public class Invoker {private Command command;public void SetCommand(Command command){this.command command;}public void ExecuteCommand(){command.Execute();} } #endregion#region 添加新的命令模式 //新命令 public class NewCommand : Command {private NewReceiver newReceiver;public NewCommand(NewReceiver newReceiver){this.newReceiver newReceiver;}public override void Execute(){newReceiver.Execute();} } //使用新接收者 public class NewReceiver {public void Execute(){Console.WriteLine(new reveiver execute the newCommand...);} }#endregion#region 命令的请求的排队和延迟执行 //命令执行者 public class CommandInvoker {private ListCommand commandQueue new ListCommand();public void AddCommand(Command command){commandQueue.Add(command);}public void ExecuteCommands(){foreach (Command command in commandQueue){command.Execute();}commandQueue.Clear();}public void DelayExecute(Command command,int delay){Console.WriteLine($等待开始....时间{delay}ms);new Thread(() {Console.WriteLine($延时执行开始);Thread.Sleep(delay);command.Execute();Console.WriteLine($finish time:{Environment.NewLine}{DateTime.Now.ToString(HH:mm:ss fff)});Console.WriteLine($延时执行完毕...);}).Start();} } #endregion#region 命令撤销和重做操作 public interface ICommand {void Execute();void Undo(); }public class HistoryCommand : ICommand {private HistoryReceiver historyReceiver;public HistoryCommand(HistoryReceiver historyReceiver){this.historyReceiver historyReceiver;}public void Execute(){historyReceiver.Execute();}public void Undo(){historyReceiver.UndoExecute();} }public class HistoryReceiver {public void Execute(){Console.WriteLine(history receiver executes the command...);}public void UndoExecute(){Console.WriteLine(history receiver undoes the command...);} } public class HistoryInvoker {private StackICommand commandStack new StackICommand();public void ExecuteCommand(ICommand command){command.Execute();commandStack.Push(command);}public void Undo(){if (commandStack.Count 0){ICommand command commandStack.Pop();Console.WriteLine(command Undo);command.Undo();}else{Console.WriteLine(No commands to undo.);}}public void Redo(){if (commandStack.Count0){ICommand command commandStack.Peek();Console.WriteLine(command Redo);command.Execute();}else{Console.WriteLine(No commands to redo.);}} }/** 行为型模式Behavioral Pattern* 命令模型Command Pattern*/internal class Program{static void Main(string[] args){//命令模式简单实现Receiver receiver new Receiver();Command sendCommand new SendCommand(receiver);Invoker invoker new Invoker();invoker.SetCommand(sendCommand);invoker.ExecuteCommand();Console.WriteLine(添加新命令------------------------------------);// 命令模式添加新命令NewReceiver newReceiver new NewReceiver();Command newCommand new NewCommand(newReceiver);invoker.SetCommand(newCommand);invoker.ExecuteCommand();Console.WriteLine(请求队列------------------------------------);//命令模式请求队列Receiver receiver1 new Receiver();Command command1 new SendCommand(receiver1);Command command2 new SendCommand(receiver1);CommandInvoker commandInvoker new CommandInvoker();commandInvoker.AddCommand(command1);commandInvoker.AddCommand(command2);commandInvoker.ExecuteCommands();Console.WriteLine(延时执行------------------------------------);Console.WriteLine(${DateTime.Now.ToString(HH:mm:ss fff)});//命令模式延时执行commandInvoker.DelayExecute(command1,1000);Console.WriteLine(准备撤销重做------------------------------------);HistoryReceiver historyReceiver new HistoryReceiver();ICommand command3 new HistoryCommand(historyReceiver);ICommand command4 new HistoryCommand(historyReceiver);HistoryInvoker historyInvoker new HistoryInvoker();historyInvoker.ExecuteCommand(command3);historyInvoker.ExecuteCommand(command4);Console.WriteLine(执行撤销重做------------------------------------);//撤销最后一个命令historyInvoker.Undo();historyInvoker.Undo();//重做最后一个撤销命令historyInvoker.Redo();Console.WriteLine(END------------------------------------);Console.ReadLine();}} #endregion运行结果
http://www.ho-use.cn/article/10821490.html

相关文章:

  • 防爆玻璃门网站建设网页qq空间登陆在线登录入口
  • wordpress 设置导航菜单襄阳seo技术
  • 长安做外贸网站长春九台建设局网站
  • 高端网站开发平台天津建设工程信息网账号密码
  • 福州网站建设网络公司排名网站总体规划说明
  • 四川大学官方网站规划建设处网站开发的技术指标
  • pc网站自动转换wap网站手机网站怎么做淘宝客
  • kesion系统做网站教程领取流量网站
  • 江苏企业网站制作哪家好html编辑器汉化版apk
  • 如何申请网站域名注册广州网站建设建航科技公司
  • 网站建设过程网页登陆界面怎么做
  • 天津装修公司做网站网站建设类毕业设计
  • 像那种代刷网站怎么做建设摩托车型号大全
  • 网站推广的工具( )新媒体运营的发展前景
  • 厦门城乡建设局网站加强旅游网站建设
  • 网站网站娱乐建设蚌埠响应式网站开发
  • 网站漏洞扫描服务ios认证 东莞网站建设
  • 广西灵山县建设局网站quercus wordpress
  • 公司网站建设手续品牌建设论文怎么写
  • 江苏网站建设网络公司安徽安搜做的网站怎么样
  • 简述网站制作过程如何自己制作网页
  • 制作制作网站建设的怎么创建小程序商店
  • 搞笑资讯网站源码张家港建设局网站
  • 郑州网站建设联系方式邢台微信群
  • 成都网站建设推广详情网络营销的目的
  • 消费返利系统网站建设服装设计网站模板下载
  • 系部网站开发项目的目的国家企业信用信息公示系统官网湖北
  • 佛山做推广网站的什么网站看电影是免费的
  • 南京哪家网站做的好自贡企业网站建设公司
  • 酒店网站建设哪家好品牌建设的内容包括