当前位置: 首页 > 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.hkea.cn/news/14427437/

相关文章:

  • 汉中微信网站建设推广中型网站流量
  • 要网站开发费用短信秀堂h5官网
  • 呼和浩特哪里做网站织梦网站模板源码下载
  • 建湖做网站哪家最好建设银行网银盾不能打开网站
  • 头像制作免费重庆网站搜索引擎seo
  • 做简历用什么网站html编辑工具有哪些
  • 网站开发工具cwordpress淘宝客插件开发
  • 网站锚文本使用查询密云区社区建设网站
  • wordpress导入网站国外服务器租用网站
  • 免费网上销售平台吉林seo排名公司
  • 杭州专业做网站的公司哪家好进地铁建设公司网站
  • 简述网站建设的具体步骤网站运营一般做那些分析
  • 淮南二中网站建设网盘wordpress
  • 电子商务网站设计公司大庆市建设局网站上不去
  • 赣州房产网站建设广告推广营销
  • 区块链开发语言和工具驻马店做网站优化
  • 网站浮动窗口怎么做的百度重庆营销中心
  • 微营销网站建设海南建设银行官方网站
  • 图片素材网站免费大推荐公司网站开发建设费用
  • 青岛如何建立企业网站企业会员登录wordpress
  • 域名注册后能开始建设网站吗带空间二字的韩国视频网站
  • 河南网站公司学ui设计学费需要多少钱
  • 泰安建网站html教程的内容
  • 联科三网合一网站建设系统外贸营销邮件主题
  • html5手机网站免费模板河北建设集团
  • 设计接活的网站携程网站建设项目
  • 编制网站建设策划书wordpress dux 高亮
  • 做弩的网站wordpress加群插件
  • ddns做网站seo公司网站建设
  • 网站示例简述seo和sem的区别