Example #1
0
        public void CheckProducts()
        {
            IPhoneFactory factory = null;

            switch (_manufacturer)
            {
            case Manufacturer.Nokia:
                factory = new NokiaFactory();
                break;

            case Manufacturer.HTC:
                factory = new HTCFactory();
                break;

            case Manufacturer.Samsung:
                factory = new SamsungFactory();
                break;

            default:
                break;
            }

            Console.WriteLine("{0}:\nSmartphone: {1}\nDumb phone: {2}", _manufacturer.ToString(), factory.GetSmart().Name,
                              factory.GetDumb().Name);
        }
        static void Main(string[] args)
        {
            IPhoneFactory samsungFactory = new SamsungFactory();
            IPhoneFactory nokiaFactory   = new NokiaFactory();

            var samsungSmartPhone = samsungFactory.GetSmartPhone();
            var samsungDumbPhone  = samsungFactory.GetDumbPhone();
            var nokiaSmartPhone   = nokiaFactory.GetSmartPhone();
            var nokiaDumbPhone    = nokiaFactory.GetDumbPhone();

            samsungSmartPhone.DoSomething();
            samsungDumbPhone.DoSomething();
        }
Example #3
0
        public static void Test()
        {
            IMobile        mobile;
            IMobileFactory factory;

            factory = new MotorolaFactory();
            mobile  = factory.ProduceMobile();
            mobile.Call();

            factory = new NokiaFactory();
            mobile  = factory.ProduceMobile();
            mobile.Call();
        }
        public static void Perform()
        {
            IPhoneFactory nokiaMobilePhone = new NokiaFactory();
            PhoneClient   nokiaClient      = new PhoneClient(nokiaMobilePhone);

            Console.WriteLine("********* NOKIA **********");
            Console.WriteLine(nokiaClient.GetSmartPhoneDetails());
            Console.WriteLine(nokiaClient.GetNormalPhoneDetails());

            IPhoneFactory samsungMobilePhone = new SamsungFactory();
            PhoneClient   samsungClient      = new PhoneClient(samsungMobilePhone);

            Console.WriteLine("******* SAMSUNG **********");
            Console.WriteLine(samsungClient.GetSmartPhoneDetails());
            Console.WriteLine(samsungClient.GetNormalPhoneDetails());
        }
Example #5
0
        public void NokiaFactoryPositiveTest()
        {
            IPhoneFactory nokiaFactory = new NokiaFactory();

            PhoneClient phoneClient     = new PhoneClient(nokiaFactory, "SmartPhone");
            var         phoneName       = phoneClient.GetPhoneName();
            var         cordedPhoneName = phoneClient.GetCordedPhoneName();

            PhoneClient phoneClient2     = new PhoneClient(nokiaFactory, "BasicPhone");
            var         phoneName2       = phoneClient2.GetPhoneName();
            var         cordedPhoneName2 = phoneClient2.GetCordedPhoneName();

            Assert.AreEqual("SmartPhone", phoneName);
            Assert.AreEqual("HomePhone", cordedPhoneName);
            Assert.AreEqual("BasicPhone", phoneName2);
            Assert.AreEqual("Payphone", cordedPhoneName2);
        }
Example #6
0
        public void TestCreatePhablet()
        {
            LumiaPhab       phablet = new LumiaPhab();
            AbstractFactory nokia   = new NokiaFactory();

            Assert.AreSame(phablet.GetType(), nokia.createPhablet().GetType());

            GalaxyNote      samsungphablet = new GalaxyNote();
            AbstractFactory samsung        = new SamsungFactory();

            Assert.AreSame(samsungphablet.GetType(), samsung.createPhablet().GetType());

            iPhonePlus      applephablet = new iPhonePlus();
            AbstractFactory apple        = new AppleFactory();

            Assert.AreSame(applephablet.GetType(), apple.createPhablet().GetType());
        }
Example #7
0
        public void TestCreateTablet()
        {
            iPad            tablet = new iPad();
            AbstractFactory apple  = new AppleFactory();

            Assert.AreSame(tablet.GetType(), apple.createTablet().GetType());

            LumiaTab        nokiatablet = new LumiaTab();
            AbstractFactory nokia       = new NokiaFactory();

            Assert.AreSame(nokiatablet.GetType(), nokia.createTablet().GetType());

            GalaxyTab       samsungtablet = new GalaxyTab();
            AbstractFactory samsung       = new SamsungFactory();

            Assert.AreSame(samsungtablet.GetType(), samsung.createTablet().GetType());
        }
Example #8
0
        public void TestCreatePhone()
        {
            GalaxyMini      phone   = new GalaxyMini();
            AbstractFactory samsung = new SamsungFactory();

            Assert.AreSame(phone.GetType(), samsung.createPhone().GetType());

            iPhone          applephone = new iPhone();
            AbstractFactory apple      = new AppleFactory();

            Assert.AreSame(applephone.GetType(), apple.createPhone().GetType());

            Lumia           nokiaphone = new Lumia();
            AbstractFactory nokia      = new NokiaFactory();

            Assert.AreSame(nokiaphone.GetType(), nokia.createPhone().GetType());
        }
Example #9
0
        static void Main(string[] args)
        {
            /*
             * Her product için ayrı ayrı Factory class'ları oluşturulur. Bu classlar Client (creator) sınıflardan
             * çağrılarak kullanılır.
             */
            var nokiaFactory = new NokiaFactory();
            var nokiaClient  = new MobileClient(nokiaFactory);

            Console.WriteLine("********* NOKIA **********");
            Console.WriteLine(nokiaClient.GetSmartPhoneModelDetails());
            Console.WriteLine(nokiaClient.GetNormalPhoneModelDetails());

            var samsungFactory = new SamsungFactory();
            var samsungClient  = new MobileClient(samsungFactory);

            Console.WriteLine("******* SAMSUNG **********");
            Console.WriteLine(samsungClient.GetSmartPhoneModelDetails());
            Console.WriteLine(samsungClient.GetNormalPhoneModelDetails());

            Console.ReadKey();
        }
Example #10
0
        static void Main(string[] args)
        {
            var userinput = "";

            WhichCompany();
            userinput = Console.ReadLine();
            int            companyid;
            IMobileFactory factory;

            while (int.TryParse(userinput, out companyid))
            {
                #region AbstractFactory
                switch (companyid)
                {
                case 1:
                    factory = new NokiaFactory();
                    break;

                case 2:
                    factory = new MotorolaFactory();
                    break;

                case 3:
                    factory = new SamsungFactory();
                    break;

                default:
                    factory = null;
                    break;
                }
                #endregion

                if (factory != null)
                {
                    WhatToMake();
                    userinput = Console.ReadLine();
                    int productid;
                    while (int.TryParse(userinput, out productid))
                    {
                        #region AbstractProduct
                        switch (productid)
                        {
                        case 1:
                            IMobile mobile = factory.CreateMobile();
                            mobile.DialNumber(123456789);
                            break;

                        case 2:
                            ICharger charger = factory.CreateCharger();
                            charger.ChargePhone(factory.CreateMobile());
                            break;

                        case 3:
                            IHeadphone headphone = factory.CreateHeadphone();
                            headphone.PlayMusic();
                            break;

                        default:

                            break;
                        }
                        #endregion
                        WhatToMake();
                        userinput = Console.ReadLine();
                    }
                }

                WhichCompany();
                userinput = Console.ReadLine();
            }
        }