zoukankan      html  css  js  c++  java
  • 设计模式学习笔记--命令模式

     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
  • 相关阅读:
    Python基础—字符串
    Python基础—函数
    2019918练手爬虫日记
    python基础—列表
    Python urllib详解
    安装TesseractOCR显示无效的路径
    Sql server 关于ID突然自增问题解决方案
    Sql server 登陆后无法找不到数据库怎么解决
    Python常用语句及流程控制
    jquery cookie操作
  • 原文地址:https://www.cnblogs.com/bzyzhang/p/5547383.html
Copyright © 2011-2022 走看看