예제 #1
0
파일: Program.cs 프로젝트: umed/patterns
        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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        static void Main(string[] args)
        {
            IGUIFactory factory = new WinFactory();
            var         app     = new Application(factory);

            app.CreateUI();
            app.Paint();

            Console.ReadLine();
        }
예제 #4
0
        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);
            }
        }