标签: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