Пример #1
0
        private static void PrintAllAnimalsRandomly()
        {
            var randomAnimalFactory = new RandomAnimalFactory();
            var randomAnimals       = CreateAnimals(randomAnimalFactory, 3);

            PrintAnimals("Random animals", randomAnimals);
        }
Пример #2
0
        static void Main(string[] args)
        {
            IAnimalFactory animalFactory = new RandomAnimalFactory();


            for (int i = 0; i < 10; i++)
            {
                var animal = animalFactory.Create();
                Console.WriteLine("The " + animal.GetType().Name + " make " + animal.MakeSound());
            }

            Console.ReadKey();
        }
Пример #3
0
        static void Main(string[] args)
        {
            IAnimalFactory factory;

            Random random = new Random();
            int    type   = random.Next(0, 2);

            if (type == 0)
            {
                factory = new BasicAnimalFactory();
            }
            else
            {
                factory = new RandomAnimalFactory();
            }

            Console.WriteLine(factory.createAnimal().GetName());
            Console.WriteLine(factory.createAnimal().GetName());
            Console.WriteLine(factory.createAnimal().GetName());
            Console.WriteLine(factory.createAnimal().GetName());
            Console.WriteLine(factory.createAnimal().GetName());
        }
Пример #4
0
        //Simulating creating animals of different types and different logic
        static void Main(string[] args)
        {
            IAnimalFactory randomAnimalFactory = new RandomAnimalFactory();

            var randomAnimal  = randomAnimalFactory.GetAnimal("Max");
            var randomAnimal2 = randomAnimalFactory.GetAnimal("Jack");
            var randomAnimal3 = randomAnimalFactory.GetAnimal("Rick");

            randomAnimal.Introduce();
            randomAnimal2.Introduce();
            randomAnimal3.Introduce();

            // Another factory

            IAnimalFactory balancedAnimalFactory = new BalancedAnimalFactory();

            var animal  = balancedAnimalFactory.GetAnimal("Max");
            var animal2 = balancedAnimalFactory.GetAnimal("Jack");
            var animal3 = balancedAnimalFactory.GetAnimal("Rick");

            animal.Introduce();
            animal2.Introduce();
            animal3.Introduce();
        }