Ejemplo n.º 1
0
        public List <IAutomobile> InputListFromConsole()
        {
            List <IAutomobile> automobiles = new List <IAutomobile>();

            Console.WriteLine("Enter size of cars(there is a basic list of machines, if you do not want to add to the list " +
                              "enter the size of the cars 0): ");
            string str   = Console.ReadLine();
            int    count = Convert.ToInt32(str);

            if (count > 0)
            {
                ShowHead();
                for (int i = 0; i < count; i++)
                {
                    string      line = Console.ReadLine();
                    IAutomobile car  = Parse(line);
                    automobiles.Add(car);
                }
            }
            else
            {
                throw new Exception("wrong size");
            }

            return(automobiles);
        }
Ejemplo n.º 2
0
    public void Stop()
    {
        car_stop = true;
        IAutomobile self = (IAutomobile)this; // cast this

        self.Stop();                          // forwarding call
    }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            AutomobileFactory factory = new AutomobileFactory();

            Console.WriteLine("case 1");
            IAutomobile audi = factory.make(AutomobileType.Audi);

            audi.start();
            audi.stop();

            IAutomobile bmw = factory.make(AutomobileType.BMW);

            bmw.start();
            bmw.stop();

            Console.WriteLine("\ncase 2");
            IAutomobile unspecified = factory.make(AutomobileType.Unspecified);

            //unspecified.start();
            //unspecified.stop();

            Console.WriteLine("\ncase 3");
            AutomobileFactory factory1 = new AutomobileFactory();
            IAutomobile       tesla    = factory1.make(AutomobileType.Tesla);

            tesla.start();
            tesla.stop();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //Case1();
            IAutomobile auto = LoadDataFromFile <IAutoFactory>().Make();

            auto.start();
            Console.ReadKey();
        }
        public static void AbstractFactoryDemo()
        {
            var         bmwFactory = new BmwFactory();
            IAutomobile myCar      = bmwFactory.CreateSportsCar();

            myCar.IntroDuce();
            Console.WriteLine(myCar.GetType().Name);
        }
Ejemplo n.º 6
0
        private static void Case1()
        {
            IAutoFactory Factory = BMWFactory.GetInstance();
            IAutomobile  auto    = Factory.Make();

            auto.start();
            auto.stop();
            Console.WriteLine(Factory);
        }
Ejemplo n.º 7
0
 AutoListVM.AutoVM AssembleAutoVM(IAutomobile auto)
 {
     return(new AutoListVM.AutoVM()
     {
         Id = auto.Id,
         Model = auto.Model,
         Name = auto.Name
     });
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            //Case1();

            IAutomobile UR = CreateInstance <TeslaFactory>().Make();

            UR.Start();
            UR.Stop();
            Console.ReadKey();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            //Case1();
            AutomobileFactory factory = AutomobileFactory.GetInstance();
            IAutomobile       auto1   = factory.Make(AutoType.AUDI);

            Console.WriteLine(auto1.GetType());
            auto1.Start();

            auto1.Stop();
        }
Ejemplo n.º 10
0
 public ComplexRule(string String, BreedEnum Breed, int Int, long Long, byte Byte, double Double, bool Bool,
                    IAutomobile car, IAutomobile[] cars)
 {
     _String = String;
     _color  = Breed;
     _Int    = Int;
     _Long   = Long;
     _Byte   = Byte;
     _Double = Double;
     _Bool   = Bool;
 }
Ejemplo n.º 11
0
        private static IAutomobile[] SetupAutomobiles()
        {
            var automobileList = new IAutomobile[]
            {
                new SubaruOutback(),
                new SUV(),
                new Truck()
            };

            return(automobileList);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            AutoMobileFactory factory = AutoMobileFactory.GetInstance();

            IAutomobile auto = factory.Make(AutoType.AUDI);

            auto.Start();
            auto.Stop();

            Type t = auto.GetType();

            Console.WriteLine(t);
        }
Ejemplo n.º 13
0
        public void Setup()
        {
            _subareOutbackMock = new SubaruOutback();
            _suvMock           = new SUV();
            _truckMock         = new Truck();

            var autoMobiles = new IAutomobile[]
            {
                _subareOutbackMock,
                _suvMock,
                _truckMock
            };

            _automobileFactory = new AutomobileFactory(autoMobiles);
        }
Ejemplo n.º 14
0
        static void Main()
        {
            IAutoFactory autoFactory = LoadFactory();

            //Caller just delegates the pobject creation to a specific factory
            //which takes the a configuration based approach to decide which factory to return and
            //which in turn decides which concrete class to return
            //Here the factory is known but the creation is centralised to specific factory
            //Also more customized objects can be created.
            IAutomobile car = autoFactory.CreateSportsCar();

            car.TurnOn();
            car.TurnOff();

            Console.ReadKey();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel(new CustomerModule());

            // Easy way to create factory. No class created, only interface.
            IAutomobileFactory factory = kernel.Get <IAutomobileFactory>(); // Instead of NEW keyword

            IAutomobile instance  = factory.CreateAutomobile("Honda", "Civic", 500);
            IAutomobile instance2 = factory.CreateAutomobile("Honda", "Jazz", 200);

            Console.WriteLine(instance.Price);
            Console.WriteLine(instance2.Price);

            // Inject dependency IInputOutputProvider into IWheaterDataProvider
            IWeatherDataProvider weather = kernel.Get <IWeatherDataProvider>();

            weather.DisplayWeatherInformation("Wonderful wheater");
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            AutomobileFactory factory = new AutomobileFactory();

            try
            {
                IAutomobile bmw = factory.make(AutoType.BMW);
                bmw.start();
                bmw.stop();
                IAutomobile audi = factory.make(AutoType.AUDI);
                audi.start();
                audi.stop();
                IAutomobile hyundai = factory.make(AutoType.UNSPECIFIED);
            }
            catch (UnspecifiedVehicleException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.Read();
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            //IAutomobile auto;
            //TeslaFactory tesla = TeslaFactory.GetInstance();
            //auto = tesla.Make();
            //auto.Start();
            //auto.Stop();

            try
            {
                IAutomobile UR = CreateInstance <TeslaFactory>().Make();


                UR.Start();
                UR.Stop();
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 18
0
        public IAutomobile make(AutomobileType type)
        {
            IAutomobile automobile = null;

            if (type == AutomobileType.Audi)
            {
                automobile = new Audi();
            }
            else if (type == AutomobileType.BMW)
            {
                automobile = new BMW();
            }
            else if (type == AutomobileType.Tesla)
            {
                automobile = new Tesla();
            }
            else
            {
                Console.WriteLine("Sorry! there is no car having this name");
                return(null);
            }
            return(automobile);
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            try {
                AutoMobileFactory factory = new AutoMobileFactory();
                IAutomobile       bmw     = factory.Make(Auto.AutoType.BMW);
                bmw.Start();
                bmw.Stop();

                IAutomobile audi = factory.Make(Auto.AutoType.AUDI);
                audi.Start();
                audi.Stop();

                IAutomobile tesla = factory.Make(Auto.AutoType.TESLA);
                tesla.Start();
                tesla.Stop();

                IAutomobile hyundai = factory.Make(Auto.AutoType.UNDEFINED);
            }catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Ejemplo n.º 20
0
 public abstract int CompareTo(IAutomobile other);
Ejemplo n.º 21
0
 public AutomobileController(IAutomobile automobile)
 {
     this._automobile = automobile;
 }
Ejemplo n.º 22
0
 public override int CompareTo(IAutomobile other)
 {
     return(this.PowerOfEngine.CompareTo(other.PowerOfEngine));
 }
Ejemplo n.º 23
0
 private void PerformSafetyChecks(IAutomobile automobile)
 {
     Logger.Write($"Performing safety checks for {automobile.Name} in AbstractFactory.UkAutomobileFactory.");
 }
Ejemplo n.º 24
0
 private void PerformCrashTests(IAutomobile automobile)
 {
     Logger.Write($"Performing crash tests for {automobile.Name} in AbstractFactory.UkAutomobileFactory.");
 }
 public ComplexRule(string String, BreedEnum Breed, int Int, long Long, byte Byte, double Double, bool Bool,
     IAutomobile car, IAutomobile[] cars)
 {
     _String = String;
     _color = Breed;
     _Int = Int;
     _Long = Long;
     _Byte = Byte;
     _Double = Double;
     _Bool = Bool;
 }
Ejemplo n.º 26
0
 public AutomobileController(IAutomobile automobile)
 {
     _auto = automobile;
 }
Ejemplo n.º 27
0
        public IAutomobile FindTheFastest(List <IAutomobile> automobiles)
        {
            IAutomobile automobile = automobiles.OrderBy(c => c.MaximumSpeed).Last();

            return(automobile);
        }
Ejemplo n.º 28
0
        public IAutomobile FindEconomical(List <IAutomobile> automobiles, double averageSpeed)
        {
            IAutomobile automobile = automobiles.OrderBy(c => c.GetVolumeOfFuel(averageSpeed)).First();

            return(automobile);
        }