static void Main(string[] args) { //状态模式 Context context = new Context(new ConcteteStateA()); context.Request(); context.Request(); context.Request(); context.Request(); WorkState.Work work = new WorkState.Work(); work.Hour = 9; work.WriteProgram(); work.Hour = 10; work.WriteProgram(); work.Hour = 12; work.WriteProgram(); work.Hour = 14; work.WriteProgram(); work.Hour = 16; work.WriteProgram(); work.Hour = 17; work.Finish = false; work.WriteProgram(); work.Hour = 19; work.WriteProgram(); work.Hour = 21; work.WriteProgram(); Console.Read(); }
public override void WriteProgram(Work work) { //throw new NotImplementedException(); if (work.Finish) { work.SetState(new RestState()); work.WriteProgram(); } else { if (work.Hour < 21) { Console.WriteLine("当前时间:{0} .在加班!累死了!", work.Hour); } else { work.SetState(new SleepingState()); work.WriteProgram(); } } }
public override void WriteProgram(Work work) { //throw new NotImplementedException(); if (work.Hour < 13) { Console.WriteLine("当前时间:{0} .饿了。犯困、午休", work.Hour); } else { work.SetState(new AfternoonState()); work.WriteProgram(); } }
public override void WriteProgram(Work work) { //throw new NotImplementedException(); if (work.Hour < 17) { Console.WriteLine("当前时间:{0} .下午状态OK,加油!", work.Hour); } else { work.SetState(new EveningState()); work.WriteProgram(); } }