Beispiel #1
0
        static void Main(string[] args)
        {
            Creator creator = new ConcreteCreatorA();

            Product prod = creator.FactoryMethod();


            Console.WriteLine(prod.GetType());
            Console.ReadKey();
        }
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // An array of creators
            Creator[] creators = new Creator[2];

            creators[0] = new ConcreteCreatorA();
            creators[1] = new ConcreteCreatorB();

            // Iterate over creators and create products
            foreach (Creator creator in creators)
            {
                Product product = creator.FactoryMethod();
                Console.WriteLine("Created {0}",
                                  product.GetType().Name);
            }

            // Wait for user
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main()
        {
            //Luuakse jada "creators", mis koosneb kahest liikmest:
            Creator[] creators = new Creator[2];
            //Need 2 jada liiget, mis tekitavad 2 uut konkreetset "creatorit", vastavalt Creatori alamklassidele ConcreteCreatorA ja ConcreteCreatorB.
            creators[0] = new ConcreteCreatorA();
            creators[1] = new ConcreteCreatorB();

            //Läbi foreach tsükli luuakse tooted, prinditakse konsoolile toote nimi
            foreach (Creator creator in creators)
            {
                Product product = creator.FactoryMethod();
                Console.WriteLine("Created {0}",
                                  product.GetType().Name);
            }



            Console.ReadLine();
        }