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

做网站有哪些公司好个人怎么建立网站

做网站有哪些公司好,个人怎么建立网站,广南网站制作,有名的app开发公司前言 命令模式的关键通过将请求封装成一个对象,使命令的发送者和接收者解耦。这种方式能更方便地添加新的命令,如执行命令的排队、延迟、撤销和重做等操作。 代码 #region 基础的命令模式 //命令(抽象类) 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 List<Command> commandQueue = new List<Command>();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 Stack<ICommand> commandStack = new Stack<ICommand>();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.Count>0){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/523613/

相关文章:

  • 做广告牌子seo外链工具
  • 微信页面设计网站兰州网络推广技术
  • 上门做网站搜狗站长工具
  • wordpress用户邮箱验证码百度seo搜索引擎优化培训
  • 360极速怎么屏蔽网站新闻热点大事件
  • 购物app开发价格表站长工具seo排名
  • 微餐饮网站建设营销型网站建设方案
  • 高端网站建设公司好不好2020国内搜索引擎排行榜
  • 网站建设服务公司选哪家比较好?苏州优化收费
  • 中国建设银行河南省分行网站推广信息哪个平台好
  • 网站建设官网免费模板杭州seo优化
  • 绍兴网站建设谷歌搜索引擎在线
  • 网站的会员认证怎么做黑龙江新闻头条最新消息
  • 做网站如何分工百度推广登录平台客服
  • 网站建设如何提案万网域名注册信息查询
  • 创意二维码制作网站企业网络营销推广案例
  • 论坛型网站怎么做百度高级检索入口
  • 做百度移动网站排搜素引擎优化
  • 公司创建一个网站需要多少钱想做百度推广找谁
  • 做文献ppt模板下载网站有哪些常德政府网站
  • 青岛网站建设公司排行外链工具在线
  • 网站怎么做显得简洁美观seo数据是什么意思
  • 阿里巴巴开通诚信通后网站怎么做网络优化网站
  • 东莞手机网站价格便宜个人免费建站软件
  • 电子商务网站建设的步骤一般为百度100%秒收录
  • 做企业网站怎么样免费的推广软件下载
  • 拓普网站建设美国搜索引擎
  • 网站开发者工资冯耀宗seo视频教程
  • 软件开发各阶段工作量比例搜索引擎优化的基础是什么
  • 网站怎么做才能将名声打响云搜索app