Example #1
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();
        }
Example #2
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);
        }