时间:2016年05月27日 | 作者 : aaronyang | 分类 : C#开发 | 浏览: 1737次 | 评论 0 人
场景:下多个命令,然后组合,其中可以撤销命令,通知命令去执行
我的实现
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StrategyMo { public abstract class Command { protected Command_Execute_Person executor; public Command(Command_Execute_Person person) { this.executor = person; } public abstract void Execute(); } public class ConcreteCommand : Command { public ConcreteCommand(Command_Execute_Person person) : base(person) { } public override void Execute() { executor.Action(); } } public class Command_Sender { private Command command; public void SetCommand(Command cmd) { this.command = cmd; } public void ExecuteCommand() { command.Execute(); } } public class Command_Execute_Person { public void Action() { Console.WriteLine("执行命令"); } } }
客户端
//准备 Command_Execute_Person p = new Command_Execute_Person(); Command c = new ConcreteCommand(p); //开始 Command_Sender i = new Command_Sender(); i.SetCommand(c); i.ExecuteCommand();
效果:
====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
抖音:wpfui 工作wpf,兴趣学习flutter
目前在合肥市某公司上班,已经厌弃,如果你的公司看的上我,加我QQ私聊
AYUI8全源码 Github地址:前往获取
杨洋(AaronYang简称AY,安徽六安人)和AY交流
高中学历,2010年开始web开发,2015年1月17日开始学习WPF
声明:AYUI7个人与商用免费,源码可购买。部分DEMO不免费
不是从我处购买的ayui7源码,我不提供任何技术服务,如果你举报从哪里买的,我可以帮你转正为我的客户,并送demo
查看捐赠AYUI7.X MVC教程 更新如下:
第一课 第二课 程序加密教程
额 本文暂时没人评论 来添加一个吧
发表评论