Exemple #1
0
        static void Main(string[] args)
        {
            string techType = Console.ReadLine();

            ITechnologyAbstractFactory abstractFactory = null;

            if (techType.ToLower() == "samsung")
            {
                abstractFactory = new SamsungFactory();
            }
            else if (techType.ToLower() == "apple")
            {
                abstractFactory = new AppleFactory();
            }

            IMobilePhone mobilePhone = abstractFactory.CreatePhone();
            ITablet      tablet      = abstractFactory.CreateTablet();

            Console.WriteLine(mobilePhone.GetType().Name);
            Console.WriteLine(tablet.GetType().Name);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Are you an apple fangirl?");

            var isFangirl = Console.ReadLine() == "yes" ? true : false;

            ITechnologyAbstractFactory techFactory = null;

            if (isFangirl)
            {
                techFactory = new AppleFactory();
            }
            else
            {
                techFactory = new SamsungFactory();
            }

            IMobilePhone myPhone  = techFactory.CreatePhone();
            ITablet      myTablet = techFactory.CreateTablet();

            Console.WriteLine(myPhone.GetType().Name);
            Console.WriteLine(myTablet.GetType().Name);
        }