private void cboPickUpCar_SelectedIndexChanged(object sender, EventArgs e) { var factory = new CarFactory(); theCar = factory.CreateCar(cboPickUpCar.Text); // Event common to all cars theCar.LegalLimitCondition += TheCar_LegalLimitCondition; // Event specific to cars of type SportsCarWithN if (theCar is SportsCarWithN) { ((SportsCarWithN)theCar).SpeedLimit += TheCar_SpeedLimit; } // refresh car's properties txtMaxSpeed.Text = theCar.MaxSpeed.ToString(); pbPhoto.Image = theCar.Photo; updateUI(); }
private void cboPickUpCar_SelectedIndexChanged(object sender, EventArgs e) { if (cboPickUpCar.Text == "Mercedes") { theCar = new SportsCarWithN("Mercedes"); // subscription to SpeedLimit depends on type ((SportsCarWithN)theCar).SpeedLimit += TheCar_SpeedLimit; } else { theCar = new SportsCar(cboPickUpCar.Text); } theCar.LegalLimitCondition += TheCar_LegalLimitCondition; // refresh car's properties txtMaxSpeed.Text = theCar.MaxSpeed.ToString(); pbPhoto.Image = theCar.Photo; updateUI(); }
public void CreateSportCar(ISportCar car) { sportCar = car; }
public Client(ICar factory) { sportCar = factory.GetSportCar(); normalCar = factory.GetNormalCar(); }