public static void Main(string[] args) { IFabricaVehiculo fabrica; Automovil[] autos = new Automovil[nAutos]; Scooter[] scooters = new Scooter[nScooters]; Console.Write("Desea utilizar " + "vehiculos electricos (1) o a gasolina (2):"); string eleccion = Console.Read().ToString(); if (eleccion.Equals("1")) { fabrica = new FabricaVehiculoElectricidad(); } else { fabrica = new FabricaVehiculoGasolina(); } for (int index = 0; index < nAutos; index++) { autos[index] = fabrica.CreaAutomovil("estandar", "amarillo", 6 + index, 3.2); } for (int index = 0; index < nScooters; index++) { scooters[index] = fabrica.CreaScooter("clasico", "rojo", 2 + index); } foreach (Automovil auto in autos) { auto.MostrarCaracteristicas(); } foreach (Scooter scooter in scooters) { scooter.MostrarCaracteristicas(); } }
public VehicleClient(VehicleFactory factory, string type) { bike = factory.GetBike(type); scooter = factory.GetScooter(type); }