public void Execute() { var products = new List <Product> { new Product("House", Color.Blue, Size.Large, 150), new Product("House", Color.Red, Size.Large, 100), new Product("Tree", Color.Green, Size.Medium, 5), new Product("Building", Color.Red, Size.Huge, 500) }; var pf = new ProductFilter(); var newProducts = pf.FilterByColor(products, Color.Red); Console.WriteLine("Product (old)"); PrintProduct(products); Console.WriteLine("Product (new)"); PrintProduct(newProducts); }
public void Execute() { var products = new List <Product> { new Product("House", Color.Blue, Size.Large, 150), new Product("House", Color.Red, Size.Large, 100), new Product("Tree", Color.Green, Size.Medium, 5), new Product("Building", Color.Red, Size.Huge, 500) }; Console.WriteLine("Product (old)"); PrintProduct(products); Console.WriteLine("=============================================="); Console.WriteLine("= Single condition filter ="); Console.WriteLine("=============================================="); var pf = new ProductFilter(); var redColorFilter = new ColorSpecification(Color.Red); var newProducts = pf.Filter(products, redColorFilter); Console.WriteLine("Product (new)"); PrintProduct(newProducts); Console.WriteLine("=============================================="); Console.WriteLine("= Multiple condition filter ="); Console.WriteLine("=============================================="); var listOfFilter = new List <ISpecification <Product> >() { new PriceSpecification(0, 150), new ColorSpecification(Color.Green) }; var andFilter = new OrSpericification(listOfFilter); var andFilterProducts = pf.Filter(products, andFilter); Console.WriteLine("Product (new)"); PrintProduct(andFilterProducts); }