コード例 #1
0
        public IVahicleManager Create(int typeCode)
        {
            IVahicleManager returnVal = null;

            if (typeCode == 1)
            {
                returnVal = new JetManager();
            }

            else if (typeCode == 2)
            {
                returnVal = new CarManager();
            }

            return(returnVal);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: waqarali12/DesignPatterns
        public static void SimpleFactory()
        {
            VahicleModel jet = new VahicleModel(1);
            VahicleModel car = new VahicleModel(2);

            //getting hold of factory
            var factory = new VahicleManagerFactory();

            //creating and consuming product/service for jet
            IVahicleManager jetManager = factory.Create(jet.TypeCode);

            jet.Engine     = jetManager.GetEngine();
            jet.HorsePower = jetManager.GetHorsePower();

            //creating and consuming product/service for car
            IVahicleManager carManager = factory.Create(car.TypeCode);

            car.Engine     = carManager.GetEngine();
            car.HorsePower = carManager.GetHorsePower();

            Console.WriteLine("-----Via Simple Factory-----");
            Console.WriteLine($"This is {jet.Engine}, having {jet.HorsePower} Horse Power\nThis is {car.Engine}, having {car.HorsePower} Horse Power");
        }