static void Main(string[] args)
        {
            IAnimalFactory tigerFactory = new TigerFactory();
            IAnimal        aTiger       = tigerFactory.CreateAnimal();

            aTiger.Speak();
            aTiger.Action();


            IAnimalFactory dogFactory = new DogFactory();
            IAnimal        aDog       = dogFactory.CreateAnimal();

            aDog.Speak();
            aDog.Action();

            Console.ReadKey();
        }
Пример #2
0
        static void Main()
        {
            Console.WriteLine("***Factory Pattern Demo***\n");

            IAnimalFactory tigerFactory = new TigerFactory();
            IAnimal        aTiger       = tigerFactory.CreateAnimal();

            aTiger.Speak();
            aTiger.Action();

            IAnimalFactory dogFactory = new DogFactory();
            IAnimal        aDog       = dogFactory.CreateAnimal();

            aDog.Speak();
            aDog.Action();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***Factory Pattern Demo.***\n");
            // Creating a Tiger Factory
            AnimalFactory tigerFactory = new TigerFactory();
            // Creating a tiger using the Factory Method
            IAnimal tiger = tigerFactory.CreateAnimal();

            tiger.AboutMe();

            // Creating a DogFactory
            AnimalFactory dogFactory = new DogFactory();
            // Creating a dog using the Factory Method
            IAnimal dog = dogFactory.CreateAnimal();

            dog.AboutMe();

            Console.ReadKey();
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Factory Pattern Demo***\n");
            // Creating a Tiger Factory
            IAnimalFactory tigerFactory = new TigerFactory();
            // Creating a tiger using the Factory Method
            IAnimal aTiger = tigerFactory.CreateAnimal();

            aTiger.Speak();
            aTiger.Action();
            // Creating a DogFactory
            IAnimalFactory dogFactory = new DogFactory();
            // Creating a dog using the Factory Method
            IAnimal aDog = dogFactory.CreateAnimal();

            aDog.Speak();
            aDog.Action();
            Console.ReadKey();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("----- Factory Method Pattern Implementation -----");
            Console.WriteLine("");

            IAnimalFactory FactoryDog = new DogFactory();
            IAnimal        animal     = FactoryDog.MakeAnimal();

            //animal.Speak();
            //animal.Action();

            Console.WriteLine("");
            IAnimalFactory FactoryCat = new CatFactory();

            animal = FactoryCat.MakeAnimal();
            //animal.Speak();
            //animal.Action();

            Console.Read();
        }
Пример #6
0
        static void Main(string[] args)
        {
            /*
             * GOF Defination - Define a Interface for creating a object, but let subclasses decide which class need to be instatiated.
             * The Factory Method Pattern lets a class differ a instantiation to subclass
             */

            Console.WriteLine("***Factory Pattern Demo***\n");
            // Creating a Tiger Factory
            IAnimalFactory tigerFactory = new TigerFactory();
            // Creating a tiger using the Factory Method
            IAnimal aTiger = tigerFactory.CreateAnimal();

            aTiger.Speak();
            aTiger.Action();
            // Creating a DogFactory
            IAnimalFactory dogFactory = new DogFactory();
            // Creating a dog using the Factory Method
            IAnimal aDog = dogFactory.CreateAnimal();

            aDog.Speak();
            aDog.Action();
            Console.ReadKey();
        }