public static void ShipProduct() { var aProduct = new Product() { Name = "Amazon Fire", Price = 100 }; var anotherProduct = new Product() { Name = "Apple TV", Price = 100 }; ProductShipper shipper = new ProductShipper(new DHL_ShippingStrategy()); shipper.ShipProduct(aProduct); shipper = new ProductShipper(new USPS_ShippingStrategy()); shipper.ShipProduct(anotherProduct); }
//public double CalculateShippingCost(ShippingMethod method) //{ // double cost = 0; // switch(method) // { // case ShippingMethod.USPS: // cost = 1.0 * 1; // break; // case ShippingMethod.Fedex: // cost = 1.0 * 2; // break; // case ShippingMethod.DHL: // cost = 1.0 * 3; // break; // case ShippingMethod.UPS: // cost = 1.0 * 4; // break; // } // return cost; //} public void ShipProduct(Product product) { // the following line makes it Polymorphic var shipping = _shippingStrategy.CalculateShippingCost(); var total = shipping + product.Price; // Charge Customer the {total} amount // Not Implemented product.Ship(total); }