Esempio n. 1
0
        static void Main(string[] args)
        {
            //Question 1
            Context ctx = new Context(new ShipSafe(0));

            ctx.LevelUp();
            ctx.LevelUp();
            ctx.TakeDamage();
            ctx.LevelUp();
            ctx.LevelUp();
            ctx.LevelUp();
            ctx.TakeDamage();
            ctx.TakeDamage();
            //Question 2
            Component root      = new Composite(2);
            Component circle1   = new Leaf(1);
            Component rectangle = new Leaf(2);

            root.AddChild(circle1);
            root.AddChild(rectangle);

            Component container1 = new Composite(1);
            Component circle2    = new Leaf(3);
            Component circle3    = new Leaf(1);

            container1.AddChild(circle2);
            container1.AddChild(circle3);

            root.AddChild(container1);

            Component container2 = new Composite(1);
            Component t1         = new Leaf(5);
            Component t2         = new Leaf(1);
            Component t3         = new Leaf(1);

            container2.AddChild(t1);
            container2.AddChild(t2);
            container2.AddChild(t3);
            root.AddChild(container2);

            root.Draw("");

            Console.WriteLine(root.countLeaf());
            //Console.WriteLine(container1.countLeaf());
            //Console.WriteLine(container2.countLeaf());
            //Console.WriteLine(t1.countLeaf());

            Console.WriteLine(isZugi(root));
            //Question 3
            CarProxy car = new CarProxy();

            // Drive the car

            car.StartDriving();
            car.showLocation();

            //Question 5
            FatalLogger fatal = new FatalLogger();
            ErrorLogger error = new ErrorLogger();
            InfoLogger  info  = new InfoLogger();

            LogBase chainRoot = fatal;

            fatal.SetNext(error);
            error.SetNext(info);
            info.SetNext(null);

            chainRoot.Log("tell me why", 2);
            Console.WriteLine("==================");

            //Question 8
            GymAccessObject gymthings = new GymBase();

            gymthings.Run();

            //Question 10
            IWindow window = new BaseWindow();

            IWindow Tlatmeimad = new TlatMeimadWindow(window);
            IWindow super      = new FlashingWindow(Tlatmeimad);

            Console.WriteLine(super.GetDetails());

            IWindow myfavoriteWindow = new Colors(new TlatMeimadWindow(new FlashingWindow(new BaseWindow())));

            Console.WriteLine(myfavoriteWindow.GetDetails());
            //Question 12
            ComputerFactoryMethod cf = new ComputerFactoryMethod();

            Computer v1 = cf.GetComputer("Gaming");
        }
Esempio n. 2
0
        public static void ChainOfRepoQuestion()
        {
            BillHandlerBase billHandler500 = new BillHandler500();
            BillHandlerBase billHandler200 = new BillHandler200();
            BillHandlerBase billHandler100 = new BillHandle100();
            BillHandlerBase billHandler25  = new BillHandle25();
            BillHandlerBase coinHandler5   = new CoinHandler5();
            BillHandlerBase coinHandler2   = new CoinHandler2();

            BillHandlerBase chainRoot = billHandler500;

            billHandler500.SetNext(billHandler200);
            billHandler200.SetNext(billHandler100);
            billHandler100.SetNext(billHandler25);
            billHandler25.SetNext(coinHandler5);
            coinHandler5.SetNext(coinHandler2);

            Console.WriteLine("748:");
            chainRoot.Handle(748);
            Console.WriteLine("==================");
            Console.WriteLine("385:");
            chainRoot.Handle(385);
            Console.WriteLine("==================");
            Console.WriteLine("400:");
            chainRoot.Handle(400);
            Console.WriteLine("==================");
            Console.WriteLine("402:");
            chainRoot.Handle(402);

            Console.WriteLine("LogsPart ============");

            LogBase fatalLogger = new FatalLogger();
            LogBase errorLogger = new ErrorLogger();
            LogBase debugLogger = new DebugLogger();
            LogBase infoLogger  = new InfoLogger();

            LogBase chainRootLog = fatalLogger;

            fatalLogger.SetNext(errorLogger);
            errorLogger.SetNext(debugLogger);
            debugLogger.SetNext(infoLogger);

            chainRootLog.Log("Dude", 1);
            Console.WriteLine("==================");
            chainRootLog.Log("Memoization", 4);
            Console.WriteLine("==================");
            chainRootLog.Log("XD TV", 3);

            LogBase chainRootLog2 = infoLogger;

            infoLogger.SetNext(debugLogger);
            debugLogger.SetNext(errorLogger);
            errorLogger.SetNext(fatalLogger);
            fatalLogger.SetNext(null);

            chainRootLog2.Log("Dude", 1);
            Console.WriteLine("==================");
            chainRootLog2.Log("Memoization", 4);
            Console.WriteLine("==================");
            chainRootLog2.Log("XD TV", 3);
        }