示例#1
0
        static void Main(string[] args)
        {
            Package package = new Package()
            {
                From = 76712, To = 10012, Weight = "1kg"
            };

            // the 3 strategies
            UPS   ups   = new UPS();
            USPS  usps  = new USPS();
            Fedex fedex = new Fedex();

            Shipping shipping = new Shipping();

            shipping.SetStrategy(ups);
            Console.WriteLine("UPS Strategy: " + shipping.Calculate(package));

            shipping.SetStrategy(usps);
            Console.WriteLine("USPS Strategy: " + shipping.Calculate(package));

            shipping.SetStrategy(fedex);
            Console.WriteLine("Fedex Strategy: " + shipping.Calculate(package));
        }
示例#2
0
        static void Main(string[] args)
        {
            Package package = new Package()
                            { From  = 76712, To = 10012, Weight = "1kg"};

            // the 3 strategies
            UPS ups = new UPS();
            USPS usps = new USPS();
            Fedex fedex = new Fedex();

            Shipping shipping = new Shipping();
            shipping.SetStrategy(ups);
            Console.WriteLine("UPS Strategy: " + shipping.Calculate(package));

            shipping.SetStrategy(usps);
            Console.WriteLine("USPS Strategy: " + shipping.Calculate(package));

            shipping.SetStrategy(fedex);
            Console.WriteLine("Fedex Strategy: " + shipping.Calculate(package));
        }