码迷,mamicode.com
首页 > 其他好文 > 详细

DesignPattern_Behavioral_Command

时间:2014-11-17 10:36:14      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   sp   for   div   

void Main()
{
    Invoker invoker = new Invoker();
    invoker.Add(new CommandA());
    invoker.Add(new CommandB());
    invoker.Notify();
}

class Receiver{
    public void ShowA(){}
    public void ShowB(){}
}
abstract class Command{
    protected Receiver receiver = new Receiver();
    public abstract void Show();
}
class CommandA:Command{
    public override void Show(){
        receiver.ShowA();
    }
}
class CommandB:Command{
    public override void Show(){
        receiver.ShowB();
    }
}
class Invoker{
    List<Command> commands = new List<Command>();
    public void Add(Command c){ commands.Add(c); }
    public void Remove(Command c){ commands.Remove(c); }
    public void Notify(){
        foreach (var command in commands)
        {
            command.Show();
        }
    }
}

 

DesignPattern_Behavioral_Command

标签:des   style   blog   io   color   ar   sp   for   div   

原文地址:http://www.cnblogs.com/rammderek/p/4102910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!