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) { 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(); }
/// <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(); }
// The client code works with an instance of a concrete creator, albeit // through its base interface. As long as the client keeps working with // the creator via the base interface, you can pass it any creator's // subclass. public void ClientCode(Creator creator) { Console.WriteLine("Client: I'm not aware of the creator's class," + "but it still works.\n" + creator.SomeOperation()); }
public void ClientCode(Creator creator) { System.Console.WriteLine("client: I am not aware of the creator class but is stil works " + creator.SomeOperation()); }
public void ClientCode(Creator creator) { Result = creator.SomeOperation(); }
static void LaunchVehicle(Creator creator) { Console.WriteLine(creator.Launch()); }