Exemplo n.º 1
0
        public void ApplyStrategy(IOfferStrategy offerStrategy)
        {
            Console.WriteLine($"Befor startgey Action {_price}");
            int finalPrice = _price - (_price * offerStrategy.GetDiscount());

            Console.WriteLine($"final price {finalPrice}");
        }
Exemplo n.º 2
0
        public void ApplyDiscount(IOfferStrategy strategy)
        {
            Console.WriteLine("Price before offer {0} ", this._price);

            decimal finalPrice = this._price - (this._price * strategy.CalculateDiscount(this._price));

            Console.WriteLine("Price after offer {0} ", finalPrice);
        }
Exemplo n.º 3
0
        public void ApplyStrategy(IOfferStrategy strategy)
        {
            /*
             * Currently applyStrategy has simple implementation.
             * You can Context for populating some more information,
             * which is required to call a particular operation
             */
            Console.WriteLine("Price before offer :" + price);
            double finalPrice
                = price - (price * strategy.GetDiscountPercentage());

            Console.WriteLine("Price after offer:" + finalPrice);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            StrategyContext context = new StrategyContext(100);

            Console.WriteLine("Enter month number between 1 and 12");
            var input = Console.ReadLine();
            int month = Convert.ToInt32(input);

            Console.WriteLine("Month =" + month);
            IOfferStrategy strategy = context.GetStrategy(month);

            context.ApplyDiscount(strategy);
            Console.ReadLine();
        }