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(); } }