예제 #1
0
        public void Run()
        {
            // 初始化电灯,原始状态为关
            Light light = new Light(new Off());

            // 第一次按下开关,打开电灯
            light.PressSwich();
            // 第二次按下开关,关闭电灯
            light.PressSwich();

            light.PressSwich();
            light.PressSwich();
        }
예제 #2
0
        /// <summary>
        /// 在关状态下,按下开关则打开电灯。
        /// </summary>
        /// <param name="light"></param>
        public override void PressSwich(Light light)
        {
            Console.WriteLine("Turn on the light.");

            light.State = new On();
        }
예제 #3
0
 public abstract void PressSwich(Light light);