publicstringSomeOperation() { var product = FactoryMethod(); var result = "Creator: The same creator's code has just worked with " + product.Operation();
// client classClient { publicvoidMain() { Console.WriteLine("App: Launched with the ConcreteCreator1."); ClientCode(new ConcreteCreator1());
Console.WriteLine(""); Console.WriteLine("App: Launched with the ConcreteCreator2."); ClientCode(new ConcreteCreator2()); }
publicvoidClientCode(Creator creator) { // ... Console.WriteLine("Client: I'm not aware of the creator's class," + "but it still works.\n" + creator.SomeOperation()); // ... } }
// program classProgram { staticvoidMain(string[] args) { new Client().Main(); // output
// App: Launched with the ConcreteCreator1. // Client: I'm not aware of the creator's class, but it still works. // Creator: The same creator's code has just worked with {Result of ConcreteProduct1}
// App: Launched with the ConcreteCreator2. // Client: I'm not aware of the creator's class, but it still works. // Creator: The same creator's code has just worked with {Result of ConcreteProduct2} }