/*public static Product[] FilterAffordableProducts(Product[] products) { var result = new ArrayList(); foreach (var product in products) { if (product.Cost < 40) result.Add(product); } return (Product[]) (result.ToArray(typeof (Product))); } public static Product[] FilterOverStockedProducts(Product[] products) { var result = new ArrayList(); foreach (var product in products) { if (product.Units > 50) result.Add(product); } return (Product[])(result.ToArray(typeof(Product))); }*/ public static Product[] Filter(Product[] products, IProductCriteria productCriteria) { var result = new ArrayList(); foreach (var product in products) { if (productCriteria.IsSatisfiedBy(product)) result.Add(product); } return (Product[])(result.ToArray(typeof(Product))); }
/*public static Product[] FilterAffordableProducts(Product[] products) * { * var result = new ArrayList(); * foreach (var product in products) * { * if (product.Cost < 40) * result.Add(product); * } * return (Product[]) (result.ToArray(typeof (Product))); * } * public static Product[] FilterOverStockedProducts(Product[] products) * { * var result = new ArrayList(); * foreach (var product in products) * { * if (product.Units > 50) * result.Add(product); * } * return (Product[])(result.ToArray(typeof(Product))); * }*/ public static Product[] Filter(Product[] products, IProductCriteria productCriteria) { var result = new ArrayList(); foreach (var product in products) { if (productCriteria.IsSatisfiedBy(product)) { result.Add(product); } } return((Product[])(result.ToArray(typeof(Product)))); }
public bool IsSatisfiedBy(Product product) { return(!_criteria.IsSatisfiedBy(product)); }
public bool IsSatisfiedBy(Product product) { return(_criteria1.IsSatisfiedBy(product) && _criteria2.IsSatisfiedBy(product)); }