Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SimpleFactory nameFact = new SimpleFactory();
            Namer         nm       = nameFact.getName(txName.Text);

            lbFirst.Text = nm.getFName();
            lbLast.Text  = nm.getLName();
        }
Esempio n. 2
0
        static void AbstractFactoryExample(int exampleNumber)
        {
            Console.WriteLine("Abstract Factory Example");

            IFactory factory;

            if (exampleNumber % 2 == 0)
            {
                factory = new SimpleFactory();
            }
            else
            {
                factory = new ComplexFactory();
            }

            var item = factory.GetItem();

            item.DoStuff();

            var otherItem = factory.GetOtherItem();

            otherItem.Sell(10);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // 1 : SINGLETON    (A : SINGLETON WITH THREAD SAFE , B : EAGER LOADING , LAZY LOADING)
            // 2 : FACTORY      (A : SIMPLE FACTORY, B : FACTORY METHOD)

MainLoop:
            Console.WriteLine(NewLine);
            Console.WriteLine("SELECT THE DESIGN PATTERN .FOR E.G. (1/2/3) : ");
            strKeyMain = Console.ReadLine().ToString();
            Console.WriteLine(NewLine);

            if (Convert.ToInt32(strKeyMain) == 1) //SINGLETONPATTERN
            {
ChildLoop1:
                Console.WriteLine("SELECT SINGLETON PATTERN TYPE. FOR E.G. (A/B/C)");
                strKeyChild = Console.ReadLine().ToString();
                if (strKeyChild.ToUpper() == "A")
                {
                    Console.WriteLine("SINGLETON WITH THREAD SAFE");
                    Parallel.Invoke(() => GetSingletonInstance_1(), () => GetSingletonInstance_2());
                }
                else if (strKeyChild.ToUpper() == "B")
                {
                    Console.WriteLine("SINGLETON WITH EAGER LOADING");
                    Parallel.Invoke(() => GetEagerSingletonInstance_1(), () => GetEagerSingletonInstance_2());
                }
                else if (strKeyChild.ToUpper() == "C")
                {
                    Console.WriteLine("SINGLETON WITH LAZY LOADING");
                    Parallel.Invoke(() => GetLazySingletonInstance_1(), () => GetLazySingletonInstance_2());
                }
                else
                {
                    goto ChildLoop1;
                }
            }
            else if (Convert.ToInt32(strKeyMain) == 2) //SIMPLE FACTORY
            {
                Console.WriteLine("SELECT FACTORY PATTERN TYPE. FOR E.G. (A/B/C)");
                strKeyChild = Console.ReadLine().ToString();

ChildLoop2:
                if (strKeyChild.ToUpper() == "A")
                {
                    Console.WriteLine("SIMPLE FACTORY PATTERN");
                    Console.WriteLine("SELECT EMPLOYEE TYPE .FOR E.G. (1,2)");
                    strKeyChilds = Console.ReadLine().ToString();
                    SimpleFactory A = new SimpleFactory();
                    A.GetEmployeeData(Convert.ToInt32(strKeyChilds));
                }
                else if (strKeyChild.ToUpper() == "B")
                {
                    Console.WriteLine("FACTORY METHOD PATTERN");
                    Console.WriteLine("SELECT EMPLOYEE TYPE .FOR E.G. (1,2)");
                    strKeyChilds = Console.ReadLine().ToString();
                    Employee emp = new Employee();
                    emp.EmployeeTypeId = Convert.ToInt32(strKeyChilds);
                    FactoryMethod a = new FactoryMethod();
                    a.GetEmployeeMethodData(emp);
                }
                else if (strKeyChild.ToUpper() == "C")
                {
                    Console.WriteLine("ABSTRACT FACTORYPATTERN");
                    Console.WriteLine("SELECT EMPLOYEE TYPE .FOR E.G. (1,2)");
                    strKeyChilds = Console.ReadLine().ToString();
                    Console.WriteLine("SELECT EMPLOYEE JOB .FOR E.G. (Manager,Others)");
                    strKeyChilds1 = Console.ReadLine().ToString();
                    Employee emp = new Employee();
                    emp.EmployeeTypeId = Convert.ToInt32(strKeyChilds);
                    emp.JobDetails     = Convert.ToString(strKeyChilds1);
                    FactoryMethod a = new FactoryMethod();
                    a.GetEmployeeAbstractFactoryData(emp);
                }
                else
                {
                    goto ChildLoop2;
                }
            }

            Console.WriteLine(NewLine);
            Console.WriteLine("WANT TO CONTINUE (Y/N)?");
            if (Console.ReadLine().ToString().ToUpper() == "Y")
            {
                goto MainLoop;
            }
        }