public PostOffice(Product product) { this.product = product; }
public double CalculateFee(int shipperId) { //product var weight = 10; var length = 30; var width = 20; var height = 10; var product = new Product { Weight = weight, Length = length, Width = width, Height = height }; IShipper shipper = GetShipper(shipperId, product); if (shipper != null) { var result = shipper.GetFee(); return result; } else { throw new NotImplementedException(); } }
private IShipper GetShipper(int shipperId, Product product) { switch (shipperId) { case 1: // 可以用 constructor, property setter, set function, factory method pattern return new Blackcat(product.Weight); case 2: return new PostOffice(product); default: return null; } }