상속: FactoryMethod.AbstractCreator
예제 #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();
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Creator creator = new ConcreteCreatorA();

            creator.AnOperation();
            creator = new ConcreteCreatorB();
            creator.AnOperation();
        }
예제 #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();
        }
예제 #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);
            }
        }
예제 #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}");
            }
        }
예제 #7
0
파일: Program.cs 프로젝트: Alex-LG/DP
        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();
        }
예제 #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();
        }
예제 #9
0
        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();
        }