Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string continent = "";

            if (args.Length >= 1)
            {
                continent = args[0]; //properties of the project >> Debug >> Aplication Arguments
            }

            //here we can see that the class (AnimalWorld) has private constructor
            IContinentFactory myContinent1 = AnimalWorld.CreateContinent(continent);  //factory

            ICarnivore myCarnivore1 = myContinent1.CreateCarnivore();                 //factory
            IHebivore  myHarbivore1 = myContinent1.CreateHerbivore();

            myCarnivore1.Hunt();
            myHarbivore1.Graze();

            Console.WriteLine(myCarnivore1.GetType().FullName);


            //Console.WriteLine("Choose continent");
            //string continent = "america";
            //Console.WriteLine("Choose continent");
            //string continent2 = Console.ReadLine();
            //var myContinent2 = AnimalWorld.CreateContinent(continent2);
            //var myC2 = myContinent2.CreateCarnivore();
            //myC2.Hunt();

            Console.ReadKey();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Contructor of Animalworld
        /// </summary>
        /// <param name="continent">Continent of the animal world that is created.</param>
        public AnimalWorld(Continent continent)
        {
            // Get fully qualified factory name
            string name = this.GetType().Namespace + "." +
                          continent.ToString() + "Factory";

            // Dynamic factory creation
            IContinentFactory factory =
                (IContinentFactory)System.Activator.CreateInstance
                    (Type.GetType(name));

            // Factory creates carnivores and herbivores
            _carnivore = factory.CreateCarnivore();
            _herbivore = factory.CreateHerbivore();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            AnimalWorld_Client world     = null;
            IContinentFactory  continent = null;
            string             result    = null;

            continent = new AmericaFactory();
            world     = new AnimalWorld_Client(continent);
            result    = world.RunFoodChain();
            Console.WriteLine(result);                      // Wolf eats Bison

            continent = new AfricaFactory();
            world     = new AnimalWorld_Client(continent);
            result    = world.RunFoodChain();
            Console.WriteLine(result);                      // Lion eats Wildebeest

            Console.ReadLine();
        }
Exemplo n.º 4
0
        // Constructor

        public AnimalWorld(IContinentFactory factory)
        {
            _carnivore = factory.CreateCarnivore();
            _herbivore = factory.CreateHerbivore();
        }
 public AnimalWorld_Client(IContinentFactory continent)
 {
     _plantEater = continent.CreatePlantEater();
     _meatEater  = continent.CreateMeatEater();
 }
Exemplo n.º 6
0
 public ContinentsFactory(IContinentFactory continentFactory)
 {
     _continentFactory = continentFactory;
 }
Exemplo n.º 7
0
 public AnimalWorld(IContinentFactory continentFactory)
 {
     herbivore = continentFactory.HerbivoreFactory();
     carnivore = continentFactory.CarnivoreFactory();
 }