Esempio n. 1
0
        static void Main(string[] args)
        {
            var modifyPrice = new ModifyPrice();
            var product     = new Product("IPhone 7", 500);

            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Decrease, 200));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 100));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Decrease, 300));

            Console.WriteLine($"I can buy just \n{product}");
        }
Esempio n. 2
0
        // Command is a Behavioral Design Pattern
        public static void Main(string[] args)
        {
            ModifyPrice modifyPrice = new ModifyPrice();
            Product     product     = new Product("Phone", 500);

            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 100));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 50));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Decrease, 25));

            Console.WriteLine(product);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var modifyPrice = new ModifyPrice();
            var product     = new Product("Toy", 50);


            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 10));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 10));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Decrease, 10));

            Console.WriteLine(product);
        }
Esempio n. 4
0
        static void Main()
        {
            var modifyPrice = new ModifyPrice();
            var product     = new Product("Phone", 500);

            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 100));

            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 50));

            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Decrease, 25));

            Console.WriteLine(product);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var modifyPrice = new ModifyPrice();
            var product     = new Product("Phone", 500);

            Execute(modifyPrice, new ProductIncreaseCommand(product, 100));

            Execute(modifyPrice, new ProductIncreaseCommand(product, 50));

            Execute(modifyPrice, new ProductDecreaseCommand(product, 25));

            Console.WriteLine(product);
        }
        static void Main(string[] args)
        {
            var modifyPrice = new ModifyPrice();
            var product     = new Product("Phone", 500);

            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 100));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Increase, 50));
            Execute(product, modifyPrice, new ProductCommand(product, PriceAction.Decrease, 2500));

            Console.WriteLine(product);
            Console.ReadLine();

            modifyPrice.UndoActions();

            Console.WriteLine(product);
            Console.ReadLine();
        }
Esempio n. 7
0
 private static void Execute(Product product, ModifyPrice modifyPrice, ICommand productCommand)
 {
     modifyPrice.SetCommand(productCommand);
     modifyPrice.Invoke();
 }