Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("-------State DEMO-------");
            Water water = new Water(new LiquidWaterState());

            water.Heat();
            water.Frost();
            water.Frost();
            water.Frost();
            Console.WriteLine();

            Console.WriteLine("-------Strategy DEMO-------");
            Coffee cofee = new Coffee(2, new Frappe());

            cofee.Prepare();
            cofee.Preparable = new ClassicCoffee();
            cofee.Prepare();
            Console.WriteLine();

            Console.WriteLine("-------Observer DEMO-------");
            ConcretePromo  promo   = new ConcretePromo();
            ConcreteClient client1 = new ConcreteClient("Olga", promo);
            ConcreteClient client2 = new ConcreteClient("Ann", promo);

            promo.PromoMarket("green tea for 10 lei!");
            client1.StopPromo();
            client2.StopPromo();
            Console.WriteLine();

            Console.WriteLine("-------Chain of Responsability DEMO-------");
            Receiver receiver = new Receiver(false, true);

            CoffeeHandler takeAndLeaveHandler = new TakeAndLeaveHandler();
            CoffeeHandler drinkInsideHandler  = new DrinkInsideHandler();

            Console.WriteLine("(Client should drink coffee)");
            drinkInsideHandler.Handle(receiver);
            takeAndLeaveHandler.Handle(receiver);
            Console.WriteLine("(Successor changes - we take two lines)");
            takeAndLeaveHandler.Successor = drinkInsideHandler;

            drinkInsideHandler.Handle(receiver);
            takeAndLeaveHandler.Handle(receiver);
            Console.WriteLine();

            Console.WriteLine("-------Command DEMO-------");
            CoffeeMachine   tv          = new CoffeeMachine();
            Sugar           sugar       = new Sugar();
            MultiController mController = new MultiController();

            mController.SetCommand(0, new CoffeeMachineOnCommand(tv));
            mController.SetCommand(1, new SugarCommand(sugar));
            // Coffee machine on
            mController.PressButton(0);
            // sugar level up
            mController.PressButton(1);
            mController.PressButton(1);
            mController.PressButton(1);
            // Undo
            mController.PressUndoButton();
            mController.PressUndoButton();
            mController.PressUndoButton();
            mController.PressUndoButton();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("-------Builder DEMO:-------");
            var coldDishesBuilder = new ColdDishesBuilder();

            Console.WriteLine("Let's build meat menu");
            var coldDishes = coldDishesBuilder.PrepareMeatMenu();

            coldDishes.showItems();
            Console.WriteLine("Total Cost: " + coldDishes.getCost());

            Console.WriteLine("Let's build veg menu");
            coldDishes = coldDishesBuilder.PrepareVegMenu();
            coldDishes.showItems();
            Console.WriteLine("Total Cost: " + coldDishes.getCost());
            Console.WriteLine();


            Console.WriteLine("-------Factory DEMO:-------");
            var         soupFactory = new SoupFactory();
            Ingredients ing1        = soupFactory.GetIngredients("ZEAMA");

            ing1.ShowIngredients();

            Ingredients ing2 = soupFactory.GetIngredients("CIORBA");

            ing2.ShowIngredients();

            Ingredients ing3 = soupFactory.GetIngredients("SALTWORT");

            ing3.ShowIngredients();

            Console.WriteLine();


            Console.WriteLine("-------Singleton DEMO:-------");
            SingleObject obj = SingleObject.GetInstance();

            obj.ShowAddress();

            Console.WriteLine();


            Console.WriteLine("-------Abstract factory DEMO:-------");
            var mondayFactory  = new ConcreteFactoryMondayMeal();
            var tuesdayFactory = new ConcreteFactoryTuesdayMeal();
            var client         = new AbstractFactoryClient(mondayFactory);

            Console.WriteLine("MONDAY Business lunch first meal: " + client.getFirstMeal());
            Console.WriteLine("MONDAY Business lunch second meal: " + client.getSecondMeal());

            client = new AbstractFactoryClient(tuesdayFactory);
            Console.WriteLine("TUESDAY Business lunch first meal: " + client.getFirstMeal());
            Console.WriteLine("TUESDAY Business lunch second meal: " + client.getSecondMeal());

            Console.WriteLine();


            Console.WriteLine("-------Prototype DEMO:-------");
            ConcretePromo originalObject = new ConcretePromo("Burger, cola", 50);

            Console.WriteLine("Original promo menu: " + originalObject.Menu + " and price: " + originalObject.Price);
            ConcretePromo clonedObject = (ConcretePromo)originalObject.Clone();

            Console.WriteLine("Cloned promo menu: " + clonedObject.Menu + " and price: " + clonedObject.Price);
        }