/* 状态模式,其实就是减少判断分支 */ static void Main(string[] args) { Weather weather = new Weather(new Low()); weather.Up(); weather.Up(); weather.Up(); Console.Read(); }
public override void Up(Weather weather) { Console.WriteLine("低温"); weather.temperatureState = new Normal(); }
public override void Up(Weather weather) { Console.WriteLine("高温"); }
public override void Up(Weather weather) { Console.WriteLine("正常"); weather.temperatureState = new Hot(); }
public abstract void Up(Weather weather);