static void Main(string[] args) { 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 pf = new ProductFilter(); Console.WriteLine("Green products (old): "); foreach (var p in pf.FilterByColor(products, Color.Green)) { Console.WriteLine($" - {p.Name} is green"); } 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 blue items:"); foreach (var p in bf.Filter(products, new AndSpecification <Product>(new ColorSpecification(Color.Blue) , new SizeSpecification(Size.Large)))) { Console.WriteLine($" - {p.Name} is big and blue"); } Console.ReadKey(); }
static void Main(string[] args) { 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 pf = new ProductFilter(); Console.WriteLine("Green products (old): "); foreach (var product in pf.FilterByColor(products, Color.Green)) { Console.WriteLine($" - {product.Name} is {product.Color}"); } Console.WriteLine("Green products (new): "); var ef = new EnchancedFilter(); foreach (var product in ef.Filter(products, new ColorSpecification(Color.Green))) { Console.WriteLine($" - {product.Name} is {product.Color}"); } Console.WriteLine("Large Blue products: "); foreach (var product in ef.Filter(products, new CombinedSpecification <Product>(new ColorSpecification(Color.Blue), new SizeSpecification(Size.Large)))) { Console.WriteLine($" - {product.Name} is {product.Color} and {product.Size}"); } Console.ReadKey(); }
static void Main(string[] args) { var apple = new Product("Apple", Color.Red, Size.M); var cherry = new Product("Cherry", Color.Red, Size.S); var orange = new Product("Orange", Color.Orange, Size.S); Product[] products = { apple, cherry, orange }; var pf = new ProductFilter(); Console.WriteLine("Red Product(OLD):"); foreach (var item in pf.FilterByColor(products, Color.Red)) { Console.WriteLine($" - {item.Name} is {item.Color}"); } var bpf = new BetterProductFilter(); Console.WriteLine("Red Product(NEW):"); foreach (var item in bpf.Filter(products, new ColorSpecification(Color.Red))) { Console.WriteLine($" - {item.Name} is {item.Color}"); } Console.WriteLine("Red and Small Product(NEW):"); foreach (var item in bpf.Filter(products, new AndSpecification <Product>( new ColorSpecification(Color.Red), new SizeSpecification(Size.S)))) { Console.WriteLine($" - {item.Name} is {item.Color} and size : {item.Size}"); } Console.ReadLine(); }
static void Main(string[] args) { Product[] products = new Product[] { new Product("Apple", Color.Green, Size.Small), new Product("Tree", Color.Green, Size.Huge), new Product("House", Color.Blue, Size.Huge) }; var pf = new ProductFilter(); foreach (var p in pf.FilterByColor(products, Color.Green)) { Console.WriteLine($" - {p.Name} is green"); } var bf = new BetterFilter(); foreach (var p in bf.Filter(products, new ColorSpecificaiton(Color.Green))) { Console.WriteLine($" - {p.Name} is green"); } var bf2 = new BetterFilter(); foreach (var p in bf2.Filter(products, new AndSpecification <Product>(new ColorSpecificaiton(Color.Green), new SizeSpecification(Size.Huge)))) { Console.WriteLine($" - {p.Name} is green and huge"); } Console.ReadKey(); // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app! }