示例#1
0
        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();
        }
示例#2
0
 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();
 }
示例#3
0
 public void CreateSportCar(ISportCar car)
 {
     sportCar = car;
 }
示例#4
0
 public Client(ICar factory)
 {
     sportCar  = factory.GetSportCar();
     normalCar = factory.GetNormalCar();
 }