コード例 #1
0
ファイル: Program.cs プロジェクト: Zgencheva/C--OOP
        static void Main(string[] args)
        {
            Console.WriteLine("Which continent you want to play?");
            string         continent = Console.ReadLine();
            IAnimalFactory factory   = new EuroFactory();

            if (continent == "Africa")
            {
                factory = new AfricaFactory();
            }
            ICarnivore carnivore = factory.GetCarnivore();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            ContinentFactory firstFactory = new AfricaFactory();
            Carnivore        firstAnimal  = firstFactory.CreateCarnivore();

            Console.WriteLine($"You could see {firstAnimal.GetType().Name} In Africa.");

            ContinentFactory secondFactory = new AmericaFactory();
            Carnivore        secondAnimal  = secondFactory.CreateCarnivore();

            Console.WriteLine($"You could see {secondAnimal.GetType().Name} In America.");

            Console.ReadLine();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Which contitnent do you want to play?");

            string contitnent = Console.ReadLine();

            IAnimalFactory factory = null;

            if (contitnent == "Africa")
            {
                factory = new AfricaFactory();
            }
            else if (contitnent == "Europe")
            {
                factory = new EuropeFactory();
            }

            ICarnivore animal = factory.GetCarnivore();
        }