static void Main(string[] args) { HelloWorldWriterType helloWorldWriterType = (HelloWorldWriterType)Enum.Parse(typeof(HelloWorldWriterType), ConfigurationManager.AppSettings["WriterType"] ?? "0"); IHelloWorldWriter writer = HelloWorldWriterFactory.GetInstance(helloWorldWriterType); writer.Write("Hello World"); Environment.Exit(0); }
public static IHelloWorldWriter GetInstance(HelloWorldWriterType type) { switch (type) { case HelloWorldWriterType.Console: return(new ConsoleHelloWorldWriter()); case HelloWorldWriterType.Database: return(new DataBaseHelloWorldWriter()); default: throw new NotImplementedException(); } }