예제 #1
0
        static void Main(string[] args)
        {
            var controller = new RemoteController();

            var tv    = new TV();
            var fan   = new Fan();
            var video = new Video();

            CommandObject videoActionOn  = new VideoActionOn(video);
            CommandObject videoActionOff = new VideoActionOff(video);
            CommandObject tvActionOn     = new TvActionOn(tv);
            CommandObject tvActionOff    = new TvActionOff(tv);
            CommandObject fanActionOn    = new FanActionOn(fan);
            CommandObject fanActionOff   = new FanActionOff(fan);

            controller.AddActionOn(videoActionOn);
            controller.AddActionOff(videoActionOff);
            controller.AddActionOn(tvActionOn);
            controller.AddActionOff(tvActionOff);
            controller.AddActionOn(fanActionOn);
            controller.AddActionOff(fanActionOff);

            Console.WriteLine(controller);

            Console.WriteLine("----> Video On");
            controller.ExecuteOn(0);
            controller.Undo();


            Console.WriteLine("----> TV On");
            controller.ExecuteOn(1);
            controller.Undo();

            Console.WriteLine("----> Fan On");
            controller.ExecuteOn(2);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOn(3);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOn(4);
            controller.Undo();

            Console.WriteLine("----> Video Off");
            controller.ExecuteOff(0);
            controller.Undo();

            Console.WriteLine("----> TV Off");
            controller.ExecuteOff(1);
            controller.Undo();

            Console.WriteLine("----> Fan Off");
            controller.ExecuteOff(2);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOff(3);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOff(4);
            controller.Undo();

            Console.WriteLine(" ---- MULTIPLE ACTIONS AND MULTIPLE UNDOES ----");
            controller.ExecuteOn(0);
            controller.ExecuteOn(1);
            controller.ExecuteOn(2);
            controller.ExecuteOff(0);
            controller.ExecuteOff(1);
            controller.ExecuteOff(2);

            controller.Undo();
            controller.Undo();
            controller.Undo();

            controller.Undo();
            controller.Undo();
            controller.Undo();

            controller.Undo();
            controller.Undo();
            controller.Undo();
            controller.Undo();
            controller.Undo();
            controller.Undo();
        }
        static void Main(string[] args)
        {
            var controller = new RemoteController();

            var tv = new TV();
            var fan = new Fan();
            var video = new Video();

            CommandObject videoActionOn = new VideoActionOn(video);
            CommandObject videoActionOff = new VideoActionOff(video);
            CommandObject tvActionOn = new TvActionOn(tv);
            CommandObject tvActionOff = new TvActionOff(tv);
            CommandObject fanActionOn = new FanActionOn(fan);
            CommandObject fanActionOff = new FanActionOff(fan);

            controller.AddActionOn(videoActionOn);
            controller.AddActionOff(videoActionOff);
            controller.AddActionOn(tvActionOn);
            controller.AddActionOff(tvActionOff);
            controller.AddActionOn(fanActionOn);
            controller.AddActionOff(fanActionOff);

            Console.WriteLine(controller);

            Console.WriteLine("----> Video On");
            controller.ExecuteOn(0);
            controller.Undo();

            Console.WriteLine("----> TV On");
            controller.ExecuteOn(1);
            controller.Undo();

            Console.WriteLine("----> Fan On");
            controller.ExecuteOn(2);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOn(3);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOn(4);
            controller.Undo();

            Console.WriteLine("----> Video Off");
            controller.ExecuteOff(0);
            controller.Undo();

            Console.WriteLine("----> TV Off");
            controller.ExecuteOff(1);
            controller.Undo();

            Console.WriteLine("----> Fan Off");
            controller.ExecuteOff(2);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOff(3);
            controller.Undo();

            Console.WriteLine("Nothing Assigned");
            controller.ExecuteOff(4);
            controller.Undo();

            Console.WriteLine(" ---- MULTIPLE ACTIONS AND MULTIPLE UNDOES ----");
            controller.ExecuteOn(0);
            controller.ExecuteOn(1);
            controller.ExecuteOn(2);
            controller.ExecuteOff(0);
            controller.ExecuteOff(1);
            controller.ExecuteOff(2);

            controller.Undo();
            controller.Undo();
            controller.Undo();

            controller.Undo();
            controller.Undo();
            controller.Undo();

            controller.Undo();
            controller.Undo();
            controller.Undo();
            controller.Undo();
            controller.Undo();
            controller.Undo();
        }
예제 #3
0
 public TvActionOff(TV tv)
 {
     this.tv = tv;
 }
 public TvActionOn(TV tv)
 {
     this.tv = tv;
 }