/// <summary>
        /// Function to calculate items cost
        /// </summary>
        /// <param name="itemElements">items to calculate costs of</param>
        /// <returns>returns total cost</returns>
        private int CalculateCost(ItemElement[] itemElements)
        {
            IShopingCartVisitor visitor = new ShoppingCartImplement();
            int total = 0;

            foreach (ItemElement item in itemElements)
            {
                total += item.Accept(visitor);
            }

            return(total);
        }
Example #2
0
        /// <summary>
        /// DisplayFunction as a function
        /// </summary>
        public static void DisplayFunction()
        {
            try
            {
                Console.WriteLine("1: Observer Patteen");
                Console.WriteLine("2: Visitor Patteen");
                Console.WriteLine("3: Mediator Patteen");
                string input = Console.ReadLine();
                if (Regex.IsMatch(input, @"^[0-9]+$"))
                {
                    int num = Convert.ToInt32(input);
                    switch (num)
                    {
                    case 1:
                        ObserverPattern.ObserverTest observerTest = new ObserverPattern.ObserverTest();
                        observerTest.ObserverFunction();
                        break;

                    case 2:
                        VisitorPattern.ShoppingCartImplement shoppingCart = new VisitorPattern.ShoppingCartImplement();
                        shoppingCart.ShoppingCartDisplay();
                        break;

                    case 3:
                        MediatorPattern.MediatorPattern mediatorPattern = new MediatorPattern.MediatorPattern();
                        mediatorPattern.MediatorFunction();
                        break;

                    default:
                        Console.WriteLine("Invalid input");
                        Console.WriteLine();
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }