private static void DoTest01() { var apple = new Product("Apple", Color.Green, Size.Small); var tree = new Product("Tree", Color.Green, Size.Large); var house = new Product("House", Color.Blue, Size.Large); Product[] products = { apple, tree, house }; var bf = new BetterFilter(); Console.WriteLine("Green products:"); ColorSpecification cs = new ColorSpecification(Color.Green); foreach (var p in bf.Filter(products, cs)) { Console.WriteLine($" - {p.Name} is green"); } Console.WriteLine("----- And Specification ----------"); SizeSpecification ss = new SizeSpecification(Size.Large); AndSpecification <Product> andSpecification = new AndSpecification <Product>(cs, ss); foreach (var p in bf.Filter(products, andSpecification)) { Console.WriteLine($" - {p.Name} is green and large"); } }
public static void Main(string[] args) { Product house = new Product("Tree", Color.Green, Size.Large); Product tree = new Product("Tree", Color.Green, Size.Medium); Product mouse = new Product("Mouse", Color.Yellow, Size.Small); Product ball = new Product("ball", Color.Yellow, Size.Large); List <Product> products = new List <Product> { house, tree, mouse, ball }; var specYellow = new ColorSpecification(Color.Yellow); var specLarge = new SizeSpecification(Size.Small); var specMultiple = new AndSpecification <Product>(new ColorSpecification(Color.Yellow), specLarge); ProductFilter productFilter = new ProductFilter(); foreach (Product yellowItem in productFilter.Filter(products, specMultiple)) { Console.WriteLine(yellowItem.Name); } }