public override void WriteProgram(Work w) { if (w.Hour < 12) Console.WriteLine(string.Format("当前上午时间 {0} 点", w.Hour)); else { w.SetState(new NooState()); w.WriteProgram(); } }
public override void WriteProgram(Work w) { if (w.Hour < 17) { Console.WriteLine("当前时间:{0},下午工作状态还可以,继续努力", w.Hour); } else { w.SetState(new EveningState()); w.WriteProgram(); } }
public override void WriteProgram(Work w) { if (w.Hour < 13) { Console.WriteLine("当前时间:{0} 点,饿了,困了,午休"); } else { w.SetState(new AfterNoonState()); w.WriteProgram(); } }
static void Main(string[] args) { //ConcreteDecoratorA a = new ConcreteDecoratorA(); //ConcreteDecoratorC c = new ConcreteDecoratorC(); //ConcreteDecoratorB b = new ConcreteDecoratorB(); //a.SetComponent(b); //b.SetComponent(c); //a.Operation(); //Console.Read(); //Student stu = new Student() { Name = "Jasper", Age = 25, Friend = new Friend { Name ="York" } }; //var stu2 = stu.Clone(); //((Student)stu2).Age = 18; //((Student)stu2).Friend.Name = "Sean"; Work w = new Work(new ForenoonState()); w.Hour = 15; w.WriteProgram(); Console.Read(); }
public override void WriteProgram(Work w) { if (w.TaskFinished) { w.SetState(new RestState()); w.WriteProgram(); } else { if (w.Hour < 21) { Console.WriteLine("当前时间:{0},疲累之极", w.Hour); } else { w.SetState(new SleepingState()); w.WriteProgram(); } } }
public override void WriteProgram(Work w) { Console.WriteLine("当前时间:{0},需要休息了", w.Hour); }
public abstract void WriteProgram(Work w);