Beispiel #1
0
        // Zdarzenie obsługujące tworzenie obiektu zupa
        private void SoupClickEvent(object sender, EventArgs e)
        {
            Button button = sender as Button;
            ISoup  soup   = SoupFactory.CreateSoup(button.Tag as FoodInformation);

            uiClbShopingCard.Items.Add(soup);
            _orderCost         += soup.Price();
            uiTxtOrderCost.Text = _orderCost.ToString("C", _cultureInfo);
        }
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);
        }