• 设计模式学习笔记--命令模式


     1 using System;
     2 
     3 namespace Command
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 20:21:09 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// Receiver说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public class Receiver
    12     {
    13         public void Action()
    14         {
    15             Console.WriteLine("执行请求!");
    16         }
    17     }
    18 }
    View Code
     1 using System;
     2 
     3 namespace Command
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 20:20:44 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// Command说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public abstract class Command
    12     {
    13         protected Receiver receiver;
    14 
    15         public Command(Receiver receiver)
    16         {
    17             this.receiver = receiver;
    18         }
    19 
    20         public abstract void Execute();
    21     }
    22 }
    View Code
     1 using System;
     2 
     3 namespace Command
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 20:23:11 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// ConcreteCommand说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public class ConcreteCommand:Command
    12     {
    13         public ConcreteCommand(Receiver receiver)
    14             : base(receiver)
    15         { }
    16 
    17         public override void Execute()
    18         {
    19             receiver.Action();
    20         }
    21     }
    22 }
    View Code
     1 using System;
     2 
     3 namespace Command
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 20:24:58 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// Invoker说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public class Invoker
    12     {
    13         private Command command;
    14 
    15         public void SetCommand(Command command)
    16         {
    17             this.command = command;
    18         }
    19 
    20        public void ExecuteCommand()
    21        {
    22            command.Execute();
    23        }
    24     }
    25 }
    View Code
     1 namespace Command
     2 {
     3     class Program
     4     {
     5         static void Main(string[] args)
     6         {
     7             Receiver receiver = new Receiver();
     8             Command command = new ConcreteCommand(receiver);
     9             Invoker invoker = new Invoker();
    10 
    11             invoker.SetCommand(command);
    12             invoker.ExecuteCommand();
    13         }
    14     }
    15 }
    View Code
  • 相关阅读:
    Element-UI中Upload上传文件前端缓存处理
    Puppeteer前端自动化测试实践
    javascript-高级用法
    什么是闭包?闭包的优缺点?
    浅谈网站性能之前端性能优化
    2019前端面试题汇总(主要为Vue)
    从官网学习Node.js FS模块方法速查
    这才是官方的tapable中文文档
    面试官问:JS的this指向
    开启梦幻般的webrtc之旅
  • 原文地址:https://www.cnblogs.com/bzyzhang/p/5547383.html
Copyright © 2020-2023  润新知