示例#1
0
        static void Main(string[] args)
        {
            //Standard builder pattern using
            Console.WriteLine("BMW car builder:");
            var bmwBuilder = new BMWBuilder();

            bmwBuilder.BuildFrame();
            bmwBuilder.BuildEngine();
            bmwBuilder.BuildWheels();
            bmwBuilder.BuildSafety();
            Console.WriteLine(bmwBuilder.GetCar());

            //Builder pattern with fabric pattern
            Console.WriteLine("\nAUDI regular car builder:");
            var audiRegular = new RegularCar(new AudiBuilder());

            Console.WriteLine(audiRegular.Construct());

            Console.WriteLine("\nBMW luxury car builder:");
            var bmwLuxury = new LuxuryCar(new BMWBuilder());

            Console.WriteLine(bmwLuxury.Construct());

            Console.ReadLine();
        }
        public T Create <T>(int id,
                            int weightInKilogram) where T : IVehicle
        {
            if (typeof(T) == typeof(IStandardCar))
            {
                IVehicle car = new StandardCar(new VehicleFees(new FeeCalculator()),
                                               id,
                                               weightInKilogram);
                return(( T )car);
            }
            if (typeof(T) == typeof(ILuxuryCar))
            {
                IVehicle car = new LuxuryCar(new VehicleFees(new FeeCalculator()),
                                             id,
                                             weightInKilogram);
                return(( T )car);
            }
            if (typeof(T) == typeof(IMotorbike))
            {
                IVehicle car = new Motorbike(new VehicleFees(new FeeCalculator()),
                                             id,
                                             weightInKilogram);
                return(( T )car);
            }
            if (typeof(T) == typeof(ITruck))
            {
                IVehicle car = new Truck(new VehicleFees(new FeeCalculator()),
                                         id,
                                         weightInKilogram);
                return(( T )car);
            }

            throw new ArgumentException("Unknown vehicle type '{0}'!".Inject(typeof(T)));
        }
        private void buttonFind_Click(object sender, RoutedEventArgs e)
        {
            List <LuxuryCar> luxuryCars    = new List <LuxuryCar>();
            XmlSerializer    xmlSerializer = new XmlSerializer(typeof(List <LuxuryCar>));

            using (Stream stream = File.OpenRead(@"..\..\XML\LuxuryCars.xml"))
            {
                luxuryCars = (List <LuxuryCar>)xmlSerializer.Deserialize(stream);
            }

            luxuryCar               = new LuxuryCar();
            luxuryCar.IsTv          = Convert.ToBoolean(checkBoxTv.IsChecked);
            luxuryCar.IsAlcohol     = Convert.ToBoolean(checkBoxAlcohol.IsChecked);
            luxuryCar.NumberOfSeats = numericUpDownAmountPeople.Value;

            for (int i = 0; i < luxuryCars.Count; ++i)
            {
                if ((luxuryCars[i].IsMatch(luxuryCar)) != null)
                {
                    luxuryCar = luxuryCars[i];
                    break;
                }
            }
            DialogResult = true;
        }
示例#4
0
        public void ShortDescription_ReturnsString_WhenCalled()
        {
            // Arrange
            var fees = Substitute.For <IVehicleFees>();
            var sut  = new LuxuryCar(fees,
                                     DefaultId,
                                     DefaultWeightInKilogram);

            // Act
            string actual = sut.ShortDescription;

            // Assert
            Assert.AreEqual("LuxuryCar",
                            actual);
        }
        private void buttonFind_Click(object sender, RoutedEventArgs e)
        {
            List <LuxuryCar> luxuryCars = new List <LuxuryCar>();

            WorkingWithXML.DeserializeLuxuryBase(ref luxuryCars, @"..\..\XML\LuxuryCars.xml");

            luxuryCar = new LuxuryCar
            {
                IsTv          = Convert.ToBoolean(checkBoxTv.IsChecked),
                IsAlcohol     = Convert.ToBoolean(checkBoxAlcohol.IsChecked),
                NumberOfSeats = numericUpDownAmountPeople.Value
            };

            for (int i = 0; i < luxuryCars.Count; ++i)
            {
                if ((luxuryCars[i].IsMatch(luxuryCar)) != null)
                {
                    luxuryCar = luxuryCars[i];
                    break;
                }
            }
            DialogResult = true;
        }
示例#6
0
 public CarsCreation(CarFactory factory)
 {
     this.luxuryCar = factory.CreatelLuxuryCar();
     this.sportCar  = factory.CreatesSportsCar();
     this.jeepCar   = factory.CreateJeepCar();
 }
示例#7
0
            public static void UseCar()
            {
                ICarBuilder luxuryCar = new LuxuryCar();
                ICarBuilder mediumCar = new MediumCar();
                ICarBuilder economyCar = new EconomyCar();

                Console.WriteLine("Car Components");
                Console.WriteLine("1. Luxury Cars");
                Console.WriteLine("2. Medium");
                Console.WriteLine("3. Economy Cars");

                CarBuilderDirector builder = new CarBuilderDirector();
                
                if (Console.ReadKey().KeyChar.ToString() == "1")
                {
                    builder.Constructor(luxuryCar);
                    luxuryCar.GetParts().ShowAllThePartsInCar();
                }
                else if (Console.ReadKey().KeyChar.ToString() == "2")
                {
                    builder.Constructor(mediumCar);
                    mediumCar.GetParts().ShowAllThePartsInCar();
                }
                else if(Console.ReadKey().KeyChar.ToString() == "3") {
                    builder.Constructor(economyCar);
                    mediumCar.GetParts().ShowAllThePartsInCar();
                }
            }
示例#8
0
 public TaxistLuxuryCarDetails(Car mainCar)
 {
     InitializeComponent();
     car = (LuxuryCar)mainCar;
 }
示例#9
0
 private void LuxuryCarPaysFee()
 {
     // 4.	Pay the outstanding fee for the luxury car
     LuxuryCar.PaysFee();
 }