public IList <Product> GetAllProductsFor(CustomerType customerType) { var discountStrategy = DiscountFactory.GetDiscountStrategyFor(customerType); var products = _productRepository.FindAll(); products.Apply(discountStrategy); return(products); }
/// <summary> /// 为全部产品赋予指定的折扣策略 /// </summary> /// <param name="customerType"></param> /// <returns></returns> public IList <Product> GetAllProductsFor(CustomerType customerType) { //1 根据传入的值通过 工厂模式去创建对应的折扣策略 IDiscountStrategy discountStrategy = DiscountFactory.GetDiscountStrategyFor(customerType); //2 获取产品仓库中的全部集合 IList <Product> products = _productRepository.FindAll(); //3 为产品仓库赋予折扣策略 products.Apply(discountStrategy); return(products); }