Beispiel #1
0
        public void CreateWehicleCheckWrongName()
        {
            WehicleFactoryFM fmp = PolandFactory.Instance;
            var car = fmp.MakeCar("MediumCareee");

            Assert.IsNull(car);
        }
Beispiel #2
0
        public void CreateWehicleChecEmptyName()
        {
            WehicleFactoryFM fmp = PolandFactory.Instance;
            WehicleFactoryFM fmc = PolandFactory.Instance;
            var carP             = fmp.MakeCar("MediumCar");
            var carC             = fmc.MakeCar("MediumCar");

            Assert.AreEqual(carP.Price, carC.Price);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            int n = 10_000_000;

            double[] times = new double[5];
            TimeSpan roznica;
            DateTime startTime, stopTime;

            var simpleFactory = WehicleFactory.Instance;
            Car car;

            startTime = DateTime.Now;
            for (int i = 0; i < n; i++)
            {
                car = simpleFactory.CreateCar("SmallCar");
            }
            stopTime = DateTime.Now;
            roznica  = stopTime - startTime;
            times[0] = roznica.TotalMilliseconds;

            startTime = DateTime.Now;
            WehicleFactoryFM factoryMethod = PolandFactory.Instance;

            for (int i = 0; i < n; i++)
            {
                car = factoryMethod.MakeCar("SmallCar") as Car;
            }
            stopTime = DateTime.Now;
            roznica  = stopTime - startTime;
            times[1] = roznica.TotalMilliseconds;

            AbstractFactory.AbstarctFactory abstractFactory = new FactoryFA(PolandFactoryAF.Instance);
            startTime = DateTime.Now;
            for (int i = 0; i < n; i++)
            {
                car = abstractFactory.CreateCar() as Car;
            }
            stopTime = DateTime.Now;
            roznica  = stopTime - startTime;
            times[2] = roznica.TotalMilliseconds;

            WehicleFactoryNoReflection wehicleFactoryNoReflection = WehicleFactoryNoReflection.Instance;

            wehicleFactoryNoReflection.RegisterProduct("SmallCar", typeof(SmallCar));
            startTime = DateTime.Now;
            for (int i = 0; i < n; i++)
            {
                car = wehicleFactoryNoReflection.CreateWehicle("SmallCar") as Car;
            }
            stopTime = DateTime.Now;
            roznica  = stopTime - startTime;
            times[3] = roznica.TotalMilliseconds;

            WehicleFactoryReflection wehicleFactoryReflection = WehicleFactoryReflection.Instance;

            wehicleFactoryReflection.RegisterProduct();

            startTime = DateTime.Now;
            for (int i = 0; i < n; i++)
            {
                car = wehicleFactoryReflection.CreateWehicle("SmallCar") as Car;
            }
            stopTime = DateTime.Now;
            roznica  = stopTime - startTime;
            times[4] = roznica.TotalMilliseconds;

            Console.WriteLine("SimpleFactory: " + times[0] + " ms");
            Console.WriteLine("FactoryMethod: " + times[1] + " ms");
            Console.WriteLine("AbstractFactory: " + times[2] + " ms");
            Console.WriteLine("NoReflection: " + times[3] + " ms");
            Console.WriteLine("Reflection: " + times[4] + " ms");
            Console.ReadKey();
        }