public void Test() { var creatorA = new ConcreteCreatorA(); var productA = creatorA.FactoryMethod(); Console.WriteLine(productA); var creatorB = new ConcreteCreatorB(); var productB = creatorB.FactoryMethod(); Console.WriteLine(productB); }
/// <summary> /// Entry point into console application. /// </summary> public void Execute() { // An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } }
/// <summary> /// Entry point into console application. /// </summary> private static void Main() { // An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } // Wait for user Console.ReadKey(); }
static void Main(string[] args) { Document[] documents = new Document[3]; documents[0] = new Resume(); documents[1] = new Report(); documents[2] = new All(); //Iterate over documents and display pages foreach (Document document in documents) { Console.WriteLine("\n" + document.GetType().Name + "--"); foreach (Page page in document.Pages) { Console.WriteLine(" " + page.GetType().Name); } } //waiting for user input for the next example Console.ReadLine(); //An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); //Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } //Wait for user Console.ReadKey(); }