private static void AddPropertiesToCategory(CategoryBase category, int id, string title, string description) { category.Id = id; category.Title = title; category.Description = description; }
static void Main(string[] args) { List <ProductBase> products = new List <ProductBase>(); List <CategoryBase> categories = new List <CategoryBase>(); ProductBase digitalBook = FactoryPattern <DigitalBook, ProductBase> .GetInstance(); AddPropertiesToProduct(digitalBook, 1, "The Old Man and the Sea", 1); products.Add(digitalBook); ProductBase movie = FactoryPattern <Movie, ProductBase> .GetInstance(); AddPropertiesToProduct(movie, 2, "Highlander", 2); products.Add(movie); movie = FactoryPattern <Movie, ProductBase> .GetInstance(); AddPropertiesToProduct(movie, 3, "Shawshank Redemption", 2); products.Add(movie); ProductBase album = FactoryPattern <MusicRecording, ProductBase> .GetInstance(); AddPropertiesToProduct(album, 4, "Iron Man Soundtrack", 3); products.Add(album); CategoryBase digitalBookCategory = FactoryPattern <DigitalBookCategory, CategoryBase> .GetInstance(); AddPropertiesToCategory(digitalBookCategory, 1, "Book", "Books digitised for download"); categories.Add(digitalBookCategory); CategoryBase movieCategory = FactoryPattern <MovieCategory, CategoryBase> .GetInstance(); AddPropertiesToCategory(movieCategory, 2, "Movie", "Movies digitised for download"); categories.Add(movieCategory); CategoryBase musicCategory = FactoryPattern <MusicCategory, CategoryBase> .GetInstance(); AddPropertiesToCategory(musicCategory, 3, "Music", "Music digitised for download"); categories.Add(musicCategory); var queryResults = GetProducts(products, categories); foreach (var result in queryResults) { Console.WriteLine($"Product Id: {result.ProductId}"); Console.WriteLine($"Title: {result.Title}"); Console.WriteLine($"Category: {result.Category}"); Console.WriteLine($"Category Description: {result.CategoryDescription}"); Console.WriteLine(); } Console.ReadKey(); }