public static Parcel GetParcel(Item item) { Parcel parcel; if (item.IsHeavyItem) { parcel = new HeavyParcel(); } else if (item.Height < 10 && item.Width < 10 && item.Depth < 10) { parcel = new SmallParcel(); } else if (item.Height < 50 && item.Width < 50 && item.Depth < 50) { parcel = new MediumParcel(); } else if (item.Height < 100 && item.Width < 100 && item.Depth < 100) { parcel = new LargeParcel(); } else { parcel = new ExtraLargeParcel(); } parcel.SetExtraWeightCost(item.Weight); return(parcel); }
public IParcel CreateParcel(IParcelSettings parcelSettings) { if (!parcelSettings.IsValid()) { throw new Exception(string.Join("\r\n", parcelSettings.GetErrors())); } if (parcelSettings.Dimensions > 0 && parcelSettings.Dimensions < 10) { var smallParcel = new SmallParcel(); smallParcel.ParcelSettings = parcelSettings; return(smallParcel); } else if (parcelSettings.Dimensions >= 10 && parcelSettings.Dimensions < 50) { var mediumParcel = new MediumParcel(); mediumParcel.ParcelSettings = parcelSettings; return(mediumParcel); } else if (parcelSettings.Dimensions >= 50 && parcelSettings.Dimensions < 100) { var largeParcel = new LargeParcel(); largeParcel.ParcelSettings = parcelSettings; return(largeParcel); } else { var XLParcel = new XLParcel(); XLParcel.ParcelSettings = parcelSettings; return(XLParcel); } }
static void Main(string[] args) { var p = new LargeParcel(); var sendByAir = new AirParcel(p); var sendByTrain = new RailParcel(p); Console.WriteLine(String.Format("{0} costs Eur: {1} to ship", sendByAir.GetDescription(), sendByAir.CalculateShippingCosts())); Console.WriteLine(String.Format("{0} costs Eur: {1} to ship", sendByTrain.GetDescription(), sendByTrain.CalculateShippingCosts())); Console.ReadLine(); }
public void SetUp() { _largeParcel = new LargeParcel(); }