コード例 #1
0
        public void TryStrategyPattern()
        {
            var newOrder1 = new MyOrder {
                ShippingMethod = ShippingOpteions.FedEx
            };
            var newOrder2 = new MyOrder {
                ShippingMethod = ShippingOpteions.UPS
            };
            var newOrder3 = new MyOrder {
                ShippingMethod = ShippingOpteions.Schenker
            };

            var shippingCostService = new CostCalculationService_WithStrategy();
            var shippingPrice1      = shippingCostService.CalculateShippingCost(newOrder1);
            var shippingPrice2      = shippingCostService.CalculateShippingCost(newOrder2);
            var shippingPrice3      = shippingCostService.CalculateShippingCost(newOrder3);

            Console.WriteLine(shippingPrice1);
            Console.WriteLine(shippingPrice2);
            Console.WriteLine(shippingPrice3);
        }
コード例 #2
0
 double CalculateForUPS(MyOrder order)
 {
     return(4.25d);
 }
コード例 #3
0
 double CalculateForFedEx(MyOrder order)
 {
     return(5.00d);
 }
コード例 #4
0
 double CalculateForSchenker(MyOrder order)
 {
     return(3.00d);
 }