static void Main(string[] args) { // 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(); }
public static void Main(string[] args) { Creator creator = new ConcreteCreatorA(); creator.AnOperation(); creator = new ConcreteCreatorB(); creator.AnOperation(); }
/// <summary> /// https://www.philipphauer.de/study/se/design-pattern/factory-method.php /// </summary> static void Main() { Creator creator = new ConcreteCreatorA(); var product = creator.CreateProduct(); Console.WriteLine(product.GetPrice()); Console.ReadKey(); }
private static void Main() { var creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (var product in creators.Select(creator => creator.FactoryMethod())) { Console.WriteLine($"{product} with class name {product.GetType().Name} created at {DateTime.Now}"); } }
static void Main(string[] args) { AbstractCreator creatorA = new ConcreteCreatorA(); IProduct productA = creatorA.FactoryMethod(); productA.Launch(); AbstractCreator creatorB = new ConcreteCreatorB(); IProduct productB = creatorB.FactoryMethod(); productB.Launch(); Console.Read(); }
static void Main(string[] args) { Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } }
/// <summary> /// Entry point into console application. /// </summary> 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 {product.GetType().Name}"); } }
static void Main(string[] args) { Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } Console.ReadKey(); }
// простое объяснение static void Main3(string[] args) { // Массив фабрик Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorN(); // Каждая фабрика создаёт свой продукт foreach (Creator creator in creators) { AbstractProduct product = creator.FactoryMethod(); Console.WriteLine("Создал {0}", product.GetType().Name); } Console.ReadKey(); }
/// <summary> /// Entry point into console application. /// </summary> static void Main() { // An array of creators var creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (var creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } // Wait for user Console.ReadKey(); }
static void Main1(string[] args) { //An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); //此產出產品A creators[1] = new ConcreteCreatorB(); //此產出產品B //Iterate over creators and create products int i = 0; foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.Blue + (i++); Console.WriteLine("Create {0}", product.GetType().Name); } Console.ReadKey(); }