Inheritance: FactoryMethod.AbstractCreator
Beispiel #1
0
        static void Main(string[] args)
        {
            // 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 #2
0
        public static void Main(string[] args)
        {
            Creator creator = new ConcreteCreatorA();

            creator.AnOperation();
            creator = new ConcreteCreatorB();
            creator.AnOperation();
        }
Beispiel #3
0
        private static void Main()
        {
            var creators = new Creator[2];
            creators[0] = new ConcreteCreatorA();
            creators[1] = new ConcreteCreatorB();

            foreach (var product in creators.Select(creator => creator.FactoryMethod()))
            {
                Console.WriteLine($"{product} with class name {product.GetType().Name} created at {DateTime.Now}");
            }
        }
        static void Main(string[] args)
        {
            AbstractCreator creatorA = new ConcreteCreatorA();
            IProduct productA = creatorA.FactoryMethod();
            productA.Launch();

            AbstractCreator creatorB = new ConcreteCreatorB();
            IProduct productB = creatorB.FactoryMethod();
            productB.Launch();

            Console.Read();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Creator[] creators = new Creator[2];
            creators[0] = new ConcreteCreatorA();
            creators[1] = new ConcreteCreatorB();

            foreach (Creator creator in creators)
            {
                Product product = creator.FactoryMethod();
                Console.WriteLine("Created {0}", product.GetType().Name);
            }
        }
Beispiel #6
0
        /// <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 {product.GetType().Name}");
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Creator[] creators = new Creator[2];

            creators[0] = new ConcreteCreatorA();
            creators[1] = new ConcreteCreatorB();
            
            foreach (Creator creator in creators)
            {
                Product product = creator.FactoryMethod();
                Console.WriteLine("Created {0}", product.GetType().Name);
            }
            
            Console.ReadKey();
        }
Beispiel #8
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // An array of creators
            var creators = new Creator[2];

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

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

            // Wait for user
            Console.ReadKey();
        }
        static void Main1(string[] args)
        {
            //An array of creators
            Creator[] creators = new Creator[2];

            creators[0] = new ConcreteCreatorA(); //此產出產品A
            creators[1] = new ConcreteCreatorB(); //此產出產品B

            //Iterate over creators and create products
            int i = 0;

            foreach (Creator creator in creators)
            {
                Product product = creator.FactoryMethod();
                Console.WriteLine();
                Console.BackgroundColor = ConsoleColor.Blue + (i++);
                Console.WriteLine("Create {0}", product.GetType().Name);
            }

            Console.ReadKey();
        }