static void Main(string[] args) { Console.WriteLine("Choose OS:"); Console.WriteLine("1. Win"); Console.WriteLine("2. OS X"); string result = Console.ReadLine(); IFactory factory; switch (result) { case "1": factory = new WinFactory(); break; case "2": factory = new OSXFactory(); break; default: throw new NotImplementedException(); } IButton button = factory.CreateButton(); ITextBox textBox = factory.CreateTextBox(); }
static void Main(string[] args) { var appearance = Appearance.IOS; IGUIFactory factory = new WinFactory(); switch (appearance) { case Appearance.Win: factory = new WinFactory(); break; case Appearance.IOS: factory = new IOSFactory(); break; } var button = factory.CreateButton(); button.Paint(); var window = factory.CreateWindow(); window.Paint(); }
static void Main(string[] args) { IGUIFactory factory = new WinFactory(); var app = new Application(factory); app.CreateUI(); app.Paint(); Console.ReadLine(); }
static void Main(string[] args) { IFactory factoryWin = new WinFactory(); IFactory factoryLin = new LinuxFactory(); IFactory factoryMac = new MacFactory(); List <IFactory> list = new List <IFactory>(new IFactory[] { factoryWin, factoryLin, factoryMac }); foreach (IFactory factory in list) { var b = factory.createButton(); var r = factory.createRadioButton(); var c = factory.createCheckBox(); Console.WriteLine("I'm {0} factory with objects:", factory.GetType().Name); Console.WriteLine("\t {0} {1} {2}", b.GetType().Name, r.GetType().Name, c.GetType().Name); } }