private static void FactoryPatternSample() { Console.WriteLine("--Sample Factory Pattern--"); ILaptopCreator lc = new DellXpsConcreteCreator(); ILaptop l = lc.GetLaptop(""); Console.WriteLine("Selected laptop is " + l.GetName() + " with a price of " + l.GetPrice()); l = lc.GetLaptop("15"); Console.WriteLine("Selected laptop is " + l.GetName() + " with a price of " + l.GetPrice()); lc = new DellGSeriesConcreteCreator(); l = lc.GetLaptop(""); Console.WriteLine("Selected laptop is " + l.GetName() + " with a price of " + l.GetPrice()); l = lc.GetLaptop("5"); Console.WriteLine("Selected laptop is " + l.GetName() + " with a price of " + l.GetPrice()); lc = new DellVostroConcreteCreator(); l = lc.GetLaptop(""); Console.WriteLine("Selected laptop is " + l.GetName() + " with a price of " + l.GetPrice()); }
private void PurchaseLaptop_button_Click(object sender, EventArgs e) { if (!re_edit_laptop) { toggleGui(); Laptop_listBox.Items.Add(laptopBeingEdited.GetName()); laptopsBought.Add(laptopBeingEdited); laptopBeingEdited = null; Info_label.Text = "0"; listbox_purchase_info.Items.Clear(); } else if (re_edit_laptop) { toggleGui(); laptopsBought.RemoveAt(Laptop_listBox.SelectedIndex); Laptop_listBox.Items.RemoveAt(Laptop_listBox.SelectedIndex); Laptop_listBox.Items.Add(laptopBeingEdited.GetName()); laptopsBought.Add(laptopBeingEdited); laptopBeingEdited = null; Info_label.Text = "0"; listbox_purchase_info.Items.Clear(); re_edit_laptop = false; } }
virtual public string GetName() { return(laptop.GetName()); }