private void button1_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex != -1 && listBox2.SelectedIndex != -1) { ICarFactory factory = listBox1.SelectedItem as ICarFactory; ICarType t = listBox2.SelectedItem as ICarType; label1.Text = factory.GetType().Name; if (t is SUV) { ISUV temp = factory.CreateSUV(); label1.Text += " " + temp.OffRoadDriving() + " " + temp.Sell(); } if (t is Hybrid) { IHybrid temp = factory.CreateHybrid(); label1.Text += " " + temp.ChargeCar() + " " + temp.Sell(); } } }
public IHybrid BuyHybrid() { return(carFactory.CreateHybrid()); }