Пример #1
0
        public void run()
        {
            IAnimalFactory oAnimalFactory1 = this._getAnimalFactory1();
            IAnimal        oAnimal1        = oAnimalFactory1.create(); //create() renvoie un IAnimal !!!

            oAnimal1.avancer();                                        //OK, tout IAnimal possède et implémente cette méthode.
            ((Mouton)oAnimal1).beler();                                //CAST obligatoire, même si je suis sûr que ce qui est retourné est un type Mouton
            //((Cheval)oAnimal1).hennir(); //INTERDIT : plante à l'exécution : convsersion impossible !

            Mouton oAnimal1b = (Mouton)oAnimalFactory1.create(); //CAST obligatoire ! car  create() renvoie un IAnimal !!!

            oAnimal1b.beler();

            //---------------

            IAnimalFactory oAnimalFactory2 = this._getAnimalFactory2(); //OK, tout IAnimal possède et implémente cette méthode.
            IAnimal        oAnimal2        = oAnimalFactory2.create();  //create() renvoie un IAnimal !!!

            oAnimal2.avancer();
            ((Cheval)oAnimal2).hennir(); //CAST obligatoire, même si je suis sûr que ce qui est retourné est un type Cheval
            //((Mouton)oAnimal2).beler(); //INTERDIT : plante à l'exécution : convsersion impossible !

            Cheval oAnimal2b = (Cheval)oAnimalFactory2.create(); //CAST obligatoire ! car  create() renvoie un IAnimal !!!

            oAnimal2b.hennir();

            Console.WriteLine("\n\n*******************\n\n");
            this.faireCrierAnimal(oAnimal1); //Mouton
            this.faireCrierAnimal(oAnimal2); //Cheval
        }
Пример #2
0
 public UserAnimalsController(IUserRepository userRepository, IAnimalFactory animalFactory, IHub hub, IOptions <AnimalOptions> animalOptions)
 {
     _userRepository = userRepository;
     _animalFactory  = animalFactory;
     _hub            = hub;
     _animalOptions  = animalOptions;
 }
Пример #3
0
 public AnimalCentre()
 {
     this.animalFactory  = new AnimalFactory();
     this.hotel          = new Hotel();
     this.procedures     = new List <IProcedure>();
     this.adoptedAnimals = new Dictionary <string, List <string> >();
 }
Пример #4
0
 public CommandInterpreter(IDatabase database, IAnimalFactory animalFactory, ICommandFactory commandFactory, OutputWriter writer)
 {
     this.Databse        = database;
     this.AnimalFactory  = animalFactory;
     this.CommandFactory = commandFactory;
     this.Writer         = writer;
 }
Пример #5
0
 public LevelFactory(IAssetProvider assetProvider, IMainHeroFactory mainHeroFactory, IAnimalFactory animalFactory, ILevelMediator gameMediator, ICoroutineRunner coroutineRunner)
 {
     _mainHeroFactory = mainHeroFactory;
     _animalFactory   = animalFactory;
     _assetProvider   = assetProvider;
     _gameMediator    = gameMediator;
     _coroutineRunner = coroutineRunner;
 }
Пример #6
0
 public Engine(IReader reader, IWriter writer, IAnimalFactory animalFactory, IFoodFactory foodFactory)
 {
     this.reader        = reader;
     this.writer        = writer;
     this.animalFactory = animalFactory;
     this.foodFactory   = foodFactory;
     this.animalsList   = new List <IAnimal>();
 }
 public PettingZooV70(
     Child aChild,
     IAnimalFactory factoryAnimal,
     IFoodFactory factoryFood)
 {
     TheChild  = aChild;
     TheAnimal = factoryAnimal.CreateAnimal(aChild.Age);
     TheFood   = factoryFood.CreateFood(aChild.MoneyLimit);
 }
Пример #8
0
        private static void FactoryExample()
        {
            IAnimalFactory factory   = AnimalFactory.CreateFactory();
            IAnimal        carnivore = factory.CreateAnimal(AnimalType.Carnivore);
            IAnimal        herbivore = factory.CreateAnimal(AnimalType.Herbivore);

            Console.WriteLine("I am a {0}, i sleep for {1} hours and like to eat {2}", carnivore.GetType().Name, carnivore.Sleep(), carnivore.Eat());
            Console.WriteLine("I am a {0}, i sleep for {1} hours and like to eat {2}", herbivore.GetType().Name, herbivore.Sleep(), herbivore.Eat());
        }
Пример #9
0
 public GameEngine(IDisplay display, IConsoleFacade facade, IHerbivoreManager herbivore, ICarnivoreManager carnivore, IAnimalFactory animalfactory, IFieldFactory fieldFactory, IGenericAnimalManager genericAnimal)
 {
     _display       = display;
     _facade        = facade;
     _herbivore     = herbivore;
     _carnivore     = carnivore;
     _animalFactory = animalfactory;
     _fieldFactory  = fieldFactory;
     _genericAnimal = genericAnimal;
 }
Пример #10
0
        private static IEnumerable <IAnimal> CreateAnimals(IAnimalFactory animalFactory, int numberOfAnimalsToCreate)
        {
            var animals = new List <IAnimal>();

            for (var i = 0; i < numberOfAnimalsToCreate; i++)
            {
                animals.Add(animalFactory.CreateAnimal());
            }

            return(animals);
        }
Пример #11
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public SavannaEngine(IAnimalFactory animalFactory, IAnimalManager animalmanager,
                      IHerbivoreManager herbivoreManager, ICarnivoreManager carnivoreManager, IView view, IConsole console)
 {
     _herbivoreManager = herbivoreManager;
     _carnivoreManager = carnivoreManager;
     _animalFactory    = animalFactory;
     _animalManager    = animalmanager;
     _console          = console;
     _view             = view;
     _field            = new();
 }
Пример #12
0
 public AnimalCentre()
 {
     this.hotel         = new Hotel();
     this.animalFactory = new AnimalFactory();
     this.chip          = new Chip();
     this.vaccinate     = new Vaccinate();
     this.fitness       = new Fitness();
     this.nailTrim      = new NailTrim();
     this.play          = new Play();
     this.dentailCare   = new DentalCare();
     this.owners        = new Dictionary <string, List <string> >();
 }
Пример #13
0
        public AnimalCentre(
            IHotel hotel,
            IAnimalFactory animalFactory,
            IProcedureFactory procedureFactory)
        {
            this.hotel            = hotel;
            this.animalFactory    = animalFactory;
            this.procedureFactory = procedureFactory;

            this.animals        = new List <IAnimal>();
            this.procedures     = new List <IProcedure>();
            this.adoptedAnimals = new Dictionary <string, List <string> >();
        }
 public UserAnimalsControllerTests()
 {
     _options = Options.Create <AnimalOptions>(new AnimalOptions
     {
         AnimalStats = new[] { new AnimalStat
                               {
                                   Code = 1,
                                   Type = "dummy"
                               } }
     });
     _userRepository = A.Fake <IUserRepository>();
     _animalFactory  = A.Fake <IAnimalFactory>();
     _hub            = A.Fake <IHub>();
 }
Пример #15
0
 public AnimalCentre()
 {
     this.hotel          = new Hotel();
     this.animalFactory  = new AnimalFactory();
     this.adoptedAnimals = new Dictionary <string, List <string> >();
     this.chip           = new Chip();
     this.dentalCare     = new DentalCare();
     this.fitness        = new Fitness();
     this.nailTrim       = new NailTrim();
     this.play           = new Play();
     this.vaccinate      = new Vaccinate();
     this.procedures     = new List <IProcedure>();
     this.AddAllProcedures();
 }
Пример #16
0
 public AnimalCentre()
 {
     this.animalFactory    = new AnimalFactory.AnimalFactory(); // zaradi namespace
     this.hotel            = new Hotel();
     this.adoptedAnimals   = new Dictionary <string, List <string> >();
     this.procedureAnimals = new Dictionary <string, IProcedure>
     {
         { "Chip", new Chip() },
         { "DentalCare", new DentalCare() },
         { "Fitness", new Fitness() },
         { "NailTrim", new NailTrim() },
         { "Play", new Play() },
         { "Vaccinate", new Vaccinate() }
     };
 }
Пример #17
0
        /// <summary>
        /// Check every animal if its mating count is equal to 3, create new animal on a field.
        /// </summary>
        public void GiveBirthToAnimal(Field field, IAnimalFactory animalFactory)
        {
            foreach (var animal in field.Animals)
            {
                if (animal.MatingCount == 3)
                {
                    animal.MatingCount = 0;

                    if (animal.ClosestPartner.ClosestPartner == animal)
                    {
                        animal.ClosestPartner.MatingCount = 0;
                    }

                    animalFactory.Create(field, animal.AnimalType);
                }
            }
        }
Пример #18
0
        public AnimalCentre(Hotel hotel, IAnimalFactory factory)
        {
            this.hotel   = hotel;
            this.factory = factory;

            procedures = new Dictionary <string, IProcedure>
            {
                { "Chip", new Chip() },
                { "DentalCare", new DentalCare() },
                { "Fitness", new Fitness() },
                { "NailTrim", new NailTrim() },
                { "Play", new Play() },
                { "Vaccinate", new Vaccinate() },
            };

            owners = new Dictionary <string, List <string> >();
        }
Пример #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Abstract Factory Pattern");

            //making a wild dog and a wild tiger with WildAnimalFactory
            IAnimalFactory animalFactory = FactoryProvider.GetAnimalFactory(AnimalType.Wild);
            IDog           dog           = animalFactory.GetDog();
            ITiger         tiger         = animalFactory.GetTiger();

            dog.AboutMe();
            tiger.AboutMe();

            Console.WriteLine("--------------------------------------------------------");

            //making a pet dog and a pet tiger with PetAnimalFactory
            animalFactory = FactoryProvider.GetAnimalFactory(AnimalType.Pet);
            dog           = animalFactory.GetDog();
            tiger         = animalFactory.GetTiger();
            dog.AboutMe();
            tiger.AboutMe();

            Console.Read();
        }
Пример #20
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Abstract Factory Pattern Demo.***\n");

            //Making a wild dog and wild tiger through WildAnimalFactory
            IAnimalFactory animalFactory = FactoryProvider.GetAnimalFactory("wild");
            IDog           dog           = animalFactory.GetDog();
            ITiger         tiger         = animalFactory.GetTiger();

            dog.AboutMe();
            tiger.AboutMe();

            Console.WriteLine("******************");

            //Making a pet dog and pet tiger through PetAnimalFactory now.
            animalFactory = FactoryProvider.GetAnimalFactory("pet");
            dog           = animalFactory.GetDog();
            tiger         = animalFactory.GetTiger();
            dog.AboutMe();
            tiger.AboutMe();

            Console.ReadLine();
        }
 public AbstractFactoryTestCases()
 {
     animalFactory = new AnimalFactory();
     foodFactory   = new FoodFactory();
 }
Пример #22
0
 public static void Initialize()
 {
     App.SimulationConfig = ConfigurationManager.GetSection("simulationConfig") as SimulationConfig;
     App.AnimalFactory    = SimulationFactory.GetAnimalFactory();
 }
Пример #23
0
 public RegisterCat(string[] data, IDatabase database, IAnimalFactory animalFactory) :
     base(data, database)
 {
     this.animalFactory = animalFactory;
 }
Пример #24
0
 public Application(IAnimalIterator animalIterator, IAnimalFactory animalFactory)
 {
     _animalIterator = animalIterator;
     _animalFactory  = animalFactory;
 }
Пример #25
0
 public ProgramHandler(IAnimalFactory animalFactory)
 {
     this.animalFactory = animalFactory;
 }
Пример #26
0
        static void Main(string[] args)
        {
            /**
             * TASK 1
             * Understanding factory method (Factory Pattern)
             * This is creating an interface that will be responsible for
             * creating the ideal factory needed given an instance
             * upon creating the right factory, the right object will be returned.
             * In this case, the IAnimalFactory returns an IAnimal (Dog or Lion) object
             * this is through CreateAnimal method of the IAnimalFactory(DogFactory ot LionFactory)
             **/
            // Factory Method.
            IAnimalFactory dogFactory = new DogFactory();
            IAnimal        dog        = dogFactory.CreateAnimal();

            IAnimalFactory lionFactory = new LionFactory();
            IAnimal        lion        = lionFactory.CreateAnimal();

            //---------------------------------------

            /**
             * Task 2
             * Manual Inversion of Control using Depedency Injection
             * Dependency injection allows applications to be loosely coupled
             * It helps to support plugable code.
             * The main objective is limit the use of the keyword 'new'
             * meaining creating a new instance of an object within another class
             * if an object is instanciated within another class, that forces dependencies
             * meaning the object that is responsible for instanciating another object is
             * strongly dependent on the object to be instanciate.
             * this can make things difficult when new functionalities are to be added
             * object implementation can change
             *
             * In the next 3 lines of code below,
             * the program handle is injected with a specific object type,
             * this can change from DogFactory to LionFactory,
             * but the implementation of ProgramHandle does not have to change,
             * it will know how to create an animal given the type of object it is provided
             * in the constructor. Ths is known as the Constructor Injection
             * (There are other types such as Property Injection or Method Injection)
             **/
            var     programHandler = new ProgramHandler(new DogFactory());
            IAnimal manuallyCreatedAnimalDependencyInjection = programHandler.CreateAnimal();


            /**
             * Task 3
             * Using DI container (Unity)
             * We use DI container's so we dont have to keep writting manual DI code
             * First we create a our bindings, I have done this in ProgramModule
             * by binding the interface to the concrete class.
             * Then get the right interface of the object passed into the kernel line 73
             * the returned object is what we use in calling CreateAnimal method.
             */
            IKernel kernel = new StandardKernel();

            kernel.Load(Assembly.GetExecutingAssembly());
            IAnimalFactory kernelAnimalFactory     = kernel.Get <DogFactory>();
            var            programHanderFromKernel = new ProgramHandler(kernelAnimalFactory);
            IAnimal        animalFromKernel        = programHanderFromKernel.CreateAnimal();

            /**
             * Reflection
             * This is just a basic explanation of reflection,
             * it is when an object checks it's own metadata for information
             * in order to be able to carry out some sort of behaviour.
             * In this case, each objec is reflection of it's self
             * so that we can use the type in a string to be displayed in our output.
             */
            WriteLine(dog.GetType(), dog);
            WriteLine(lion.GetType(), lion);
            WriteLine(manuallyCreatedAnimalDependencyInjection.GetType(),
                      manuallyCreatedAnimalDependencyInjection);
            WriteLine(animalFromKernel.GetType(), animalFromKernel);

            Console.ReadLine();
        }
Пример #27
0
 public ProgramHandler(IAnimalFactory animalFactory)
 {
     this.animalFactory = animalFactory;
 }
Пример #28
0
 public PettingZooV60(Child aChild, IAnimalFactory aFactory)
 {
     TheChild  = aChild;
     TheAnimal = aFactory.CreateAnimal(aChild.Age);
 }
 public GenericAnimalManager(ICalculations math, IAnimalValidator validator, IAnimalFactory animalFactory)
 {
     _math          = math;
     _validator     = validator;
     _animalFactory = animalFactory;
 }