static void Main2(string[] args) { var apple = new ProductBad("Apple", Color.Green, Size.Small); var tree = new ProductBad("Tree", Color.Green, Size.Large); var house = new ProductBad("House", Color.Blue, Size.Large); ProductBad[] products = { apple, tree, house }; var bf = new BetterFilter(); Console.WriteLine("Green products (new):"); foreach (var p in bf.Filter(products, new ColorSpecification(Color.Green))) { Console.WriteLine($" - {p.Name} is green"); } Console.WriteLine("Large products"); foreach (var p in bf.Filter(products, new SizeSpecification(Size.Large))) { Console.WriteLine($" - {p.Name} is large"); } Console.WriteLine("Large blue items"); foreach (var p in bf.Filter(products, new AndSpecification <ProductBad>(new ColorSpecification(Color.Blue), new SizeSpecification(Size.Large))) ) { Console.WriteLine($" - {p.Name} is big and blue"); } }
static void Main2(string[] args) { var apple = new ProductBad("Apple", Color.Green, Size.Small); var tree = new ProductBad("Tree", Color.Green, Size.Large); var house = new ProductBad("House", Color.Blue, Size.Large); ProductBad[] products = { apple, tree, house }; var pf = new ProductFilter(); Console.WriteLine("Green products (old):"); foreach (var p in pf.FilterByColor(products, Color.Green)) { Console.WriteLine($" - {p.Name} is green"); } }
public bool IsSatisfied(ProductBad p) { return(first.IsSatisfied(p) && second.IsSatisfied(p)); }