Exemple #1
0
 public override double Calculate(Package package)
 {
     // calculations...
     return 39.40;
 }
Exemple #2
0
 public double Calculate(Package package)
 {
     return company.Calculate(package);
 }
Exemple #3
0
 public abstract double Calculate(Package package);
Exemple #4
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));
        }