设计模式一:策略模式
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StrategyTest { class ZhaoYun { static void Main(string[] args) { Context context; context = new Context(new Green()); context.Operate(); Console.Read(); } } public interface IStrategy { void Operate(); } class Red:IStrategy { public void Operate() { Console.WriteLine("Open the Red Strategy:zou hou men "); } } class Green:IStrategy { public void Operate() { Console.WriteLine("Open the Red Strategy:zu ji zhui bing"); } } class Context { private IStrategy strategy; public Context(IStrategy s) { this.strategy = s; } public void Operate() { this.strategy.Operate(); } } }