Ejemplo n.º 1
0
        public IList <Product> GetProductsFor(CustomerType type)
        {
            IDiscountStrategy strategy = DiscountFactory.GetDiscountStrategy(type);
            IList <Product>   products = _repository.FindAll();

            products.ApplyDiscountStrategy(strategy);
            return(products);
        }
Ejemplo n.º 2
0
        public IList <Product> GetAllProductsFor(CustomerType customerType)
        {
            var discountStrategy = DiscountFactory.GetDiscountStrategyFor(customerType);
            var products         = _productRepository.FindAll();

            products.Apply(discountStrategy);
            return(products);
        }
Ejemplo n.º 3
0
        /// <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);
        }