public override void WriteProgram(Work w) { if (w.Finished) { w.State = new RestState(); w.DoWork(); } else { if (w.Hour < 21) { Console.WriteLine("时间:{0},加班",w.Hour); } else { w.State = new SleepingState(); w.DoWork(); } } }
public override void WriteProgram(Work w) { if (w.Hour < 12) { Console.WriteLine("时间:{0},精力充沛", w.Hour); } else { w.State = new NoonState(); w.DoWork(); } }
public override void WriteProgram(Work w) { if (w.Hour < 13) { Console.WriteLine("时间:{0},下午想睡觉", w.Hour); } else { w.State = new EvningState(); w.DoWork(); } }
public override void WriteProgram(Work w) { if (w.Hour < 13) { Console.WriteLine("时间:{0},饿了,午饭快点来吧", w.Hour); } else { w.State = new AfternooState(); w.DoWork(); } }
static void Main(string[] args) { Work w = new Work(); w.Finished = false; w.Hour = 9; w.State = new ForenoonState(); w.DoWork(); w.Hour = 10; w.DoWork(); w.Hour = 13; w.DoWork(); w.Hour = 15; w.DoWork(); w.Hour = 22; w.DoWork(); }